Hand over data taken over from the Android server to other activities

Asked 2 years ago, Updated 2 years ago, 49 views

Development tools: Android Studio, Cafe 24 Server (DB), php, MySql

Creating bulletin board. I even expressed the title of the posts currently stored in the DB as a list view. Now, if you click on the list view with the title, you can move on to other activities and implement the title/author/date/content.


The contents of the backgroundTask2 onPostExecute.

        @Override
        protected void onPostExecute(String result) {

            try {
                JSONObject jsonObject = new JSONObject(result);
                JSONArray jsonArray = jsonObject.getJSONArray("response");
                int count = 0;
                String POST_TITLE, POST_USER, POST_TS , POST_CONTENT;

                while(count < jsonArray.length()) {
                    JSONObject object = jsonArray.getJSONObject(count);
                    POST_TITLE = object.getString("POST_TITLE");
                    POST_USER = object.getString("POST_USER");
                    POST_TS = object.getString("POST_TS");
                    POST_CONTENT = object.getString("POST_CONTENT");

                    BoardSelect boardSelect = new BoardSelect(POST_TITLE, POST_USER, POST_TS, POST_CONTENT);
                    boardSelectList.add(boardSelect);
                    count++;
                }

            } } catch (Exception e) {
                e.printStackTrace();
            }
        }

The above code is the data from the DB to be imported when you click the list view. When I filmed it with Sysout, the data came in well one by one. I even brought it like this, but if I turn over the int like this, everything in the DB will be transferred together. When I click on a list view, I don't know how to implement the data of that list view separately and spray it on activities.


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

                new BackgroundTask2().execute();


            }
        });

I think when you click on the list view, you can do something with the position... I can't google this and that, so I'm posting a question.

android array listview

2022-09-21 10:41

2 Answers

From the list of data in the DB that you handed over to the list view, You only need to extract the data that fits the position of the clicked list view.


2022-09-21 10:41

                POST_TITLE = object.getString("POST_TITLE");
                POST_USER = object.getString("POST_USER");
                POST_TS = object.getString("POST_TS");
                POST_CONTENT = object.getString("POST_CONTENT");

Don't take the string one by one. Just put it in the arrangement

ArrayList<String> POST_TITLE = new ArrayList<>();

POST_TITLE.add(object.getString("POST_TITLE") 

If you make an arrangement like this and put it in,

 //query inquiry
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Intent intent = new Intent(MainActivity.this, SelectActivity.class);
            //List Position = Array Position
            intent.putExtra("POST_TITLE",POST_TITLE.get(position));
           //If I do this, the title in the clicked position will go over, right?

        new BackgroundTask2().execute();


        }
    });


2022-09-21 10:41

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.