안드로이드 게시판 내용 가져오기

조회수 474회

전에 하다가 다른일때매 잠시 미뤄두고 있던 게시판을 다시 만들고있습니다.

그런데 예전에 막혔던 부분에서 또 막혀서 더이상 진행이 안 되고있습니다 ㅠ

게시판 리스트를 불러오고 리스트를 클릭하면 해당 내용들을 가져오는 부분을 짜고있는데 막혔습니다. 서버는 카페24를 이용중입니다.

class SelectBoard extends AsyncTask<Void, Void, String> {
        String target;

        @Override
        protected void onPreExecute() {
            target = "php파일";
        }

        @Override
        protected String doInBackground(Void... voids) {
            try {
                URL url = new URL(target);
                HttpURLConnection httpURLConnection = (HttpURLConnection)url.openConnection();
                InputStream inputStream = httpURLConnection.getInputStream();
                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
                String temp;
                StringBuilder stringBuilder = new StringBuilder();

                while((temp = bufferedReader.readLine()) != null) {
                    stringBuilder.append(temp + "\n");
                }

                bufferedReader.close();
                inputStream.close();
                httpURLConnection.disconnect();

                return stringBuilder.toString().trim();
            } catch(Exception e) {
                e.printStackTrace();
            }
            return null;
        }

        @Override
        protected void onProgressUpdate(Void... values) {
            super.onProgressUpdate(values);
        }

        @Override
        protected void onPostExecute(String result) {
            try {
                JSONObject jsonObject = new JSONObject(result);
                JSONArray jsonArray = jsonObject.getJSONArray("response");
                int count = 0;

                while(count < jsonArray.length()) {
                    JSONObject object = jsonArray.getJSONObject(count);
                    titleText = object.getString("boardTitle");
                    userText = object.getString("userName");
                    dateText = object.getString("boardTS");
                    contentText = object.getString("boardContent");
                    count++;
                }
            } catch(Exception e) {
                e.printStackTrace();
            }
        }
    }

이렇게 php파일을 통해 DB테이블을 읽어오게끔 했고 밑에는 리스트뷰를 클릭했을 때 입니다.

listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                new SelectBoard().execute();
                Intent intent = new Intent(MainActivity.this, ShowBoardActivity.class);

                if(adapter.getItem(position) != null) {
                    intent.putExtra("title", titleText);
                    System.out.println("title : " + titleText);
                    intent.putExtra("user", userText);
                    System.out.println("user : " + userText);
                    intent.putExtra("date", dateText);
                    System.out.println("date : " + dateText);
                    intent.putExtra("content", contentText);
                    System.out.println("content : " + contentText);
                } else {
                    Toast.makeText(getApplicationContext(), "데이터 가져오기 실패", Toast.LENGTH_SHORT).show();
                }
                startActivity(intent);
            }
        });

임시로 데이터를 저렇게 넣었습니다. 리스트뷰를 클릭했을 때 리스트뷰의 아이디와 맞는 값들만 불러오고싶습니다. 그런데 그 부분을 어떻게 짜야하는지 모르겠습니다. 제가 회원가입부분만 유튜브를 보고 공부하고 나머지는 그걸 토대로 하고있어서 아직 잘 몰라 질문 올립니다.

  • (•́ ✖ •̀)
    알 수 없는 사용자

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)