Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6372245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:12:44+00:00 2026-05-25T01:12:44+00:00

I have two listviews, clicking an item on the first list view loads the

  • 0

I have two listviews, clicking an item on the first list view loads the second listview, with a new list of items (depending on what the user clicked on in the first list).

Basically, the second list view keeps loading the same list everytime, even though the user is selecting different items on the first list. It seems like the onItemClick isnt getting called or something similar.

Here’s the code:

        listview.setOnItemClickListener(new OnItemClickListener(){

            public void onItemClick(AdapterView<?> a, View v, int position, long id) {
                Object item = listview.getItemAtPosition(position);

                //Log.v(LOG_TAG,"selected item: " + item);
                SavePreferences("item",item.toString());
    fetchNewList();
                 flipper.showNext();
            }});

        listview2.setOnItemClickListener(new OnItemClickListener(){
            public void onItemClick(AdapterView<?> a, View v, int position, long id) {
                 flipper.showPrevious();
            }});

 @SuppressWarnings("null")
    public ArrayList<String> fetch()
    {
        ArrayList<String> listItems = new ArrayList<String>();
        try {
            URL twitter = new URL(
                    "JSON.php");
            URLConnection tc = twitter.openConnection();
            BufferedReader in = new BufferedReader(new InputStreamReader(
                    tc.getInputStream()));
            String line;
            while ((line = in.readLine()) != null) {
          //make sure youe String line is completely filled after that..
          if (!line.equals(null) && !line.equals("") && line.startsWith("[")) 
           {
          JSONArray jArray = new JSONArray(line);
          Log.v(LOG_TAG,"jarray value: " + jArray);
          for (int i = 0;i < jArray.length(); i++) 
           {
             //SONObject jobj = jArray.getJSONObject(i);
              String country = jArray.getString(i);
              listItems.add(country); 
             // also make sure you get the value from the jsonObject using some key
             // like, jobj.getString("country");
            //istItems.add(jobj.getString(""));
           }
              }
            } 
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return listItems;
    }
    @SuppressWarnings("null")
    public ArrayList<String> fetchNewList()
    {
        ArrayList<String> listItems = new ArrayList<String>();
        try {
            SharedPreferences sharedPreferences = getSharedPreferences("MY_SHARED_PREF", MODE_PRIVATE);
            String selectedcounty = sharedPreferences.getString("item", "");
            Log.v(LOG_TAG,"ITEM**:" + selecteditem);
            URL twitter = new URL(
                    "JSON2.php?item=" + selecteditem);
            URLConnection tc = twitter.openConnection();
            BufferedReader in = new BufferedReader(new InputStreamReader(
                    tc.getInputStream()));

        String line;
            while ((line = in.readLine()) != null) {
          //make sure youe String line is completely filled after that..
          if (!line.equals(null) && !line.equals("") && line.startsWith("[")) 
           {

          JSONArray jArray = new JSONArray(line);
         // Log.v(LOG_TAG,"jarray value: " + jArray);
          for (int i = 0;i < jArray.length(); i++) 
           {
             //SONObject jobj = jArray.getJSONObject(i);
              String country = jArray.getString(i);
              listItems.add(country); 
             // also make sure you get the value from the jsonObject using some key
             // like, jobj.getString("country");
            //istItems.add(jobj.getString(""));
           }
              }
            } 
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return listItems;
    }
    @Override
    public void onClick(View arg0) {
        // TODO Auto-generated method stub

    }
       private void SavePreferences(String key, String value){
            SharedPreferences sharedPreferences = getSharedPreferences("MY_SHARED_PREF", MODE_PRIVATE);
            SharedPreferences.Editor editor = sharedPreferences.edit();
            editor.putString(key, value);
            editor.commit();
           }

UPDATE: Got it working, I created a new method, called public void refreshNewList(), and put the following code in it:

adapter2 = null;
        adapter2 = new ArrayAdapter(this,android.R.layout.simple_list_item_1,this.fetchNewList());
        listview2.setAdapter(adapter2);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T01:12:44+00:00Added an answer on May 25, 2026 at 1:12 am
            listview.setOnItemClickListener(new OnItemClickListener(){
    
            public void onItemClick(AdapterView<?> a, View v, int position, long id) {
                Object item = listview.getItemAtPosition(position);
    
                //Log.v(LOG_TAG,"selected item: " + item);
                SavePreferences("item",item.toString());
                listview2.setAdapter(new YourAdapter(context, resource, fetchNewList()));
    
                flipper.showNext();
            }});
    

    EDIT: Try this

    adapter2 = null; 
    adapter2 = new YourAdapter(paramters); 
    listview2.setdapter(adapter2);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two ListViews, the second view items change according to what the first
I have two listViews on the page. I select Item in the first one
I have a listview with several items that are created dynamically, each has two
I have two user controls on the same page. One contains a ListView that
I have two ListViews (A and B) with items of the same type (a
I have a vertical linear layout with two ListViews. I want the top ListView
I have an activity that has two tabs and a list view in each.
I have two listviews, one where the data is displayed and another where I
I have a RelativeLayout with different elements. I was planning to have two ListViews
I have a page with two Listviews (with two different data sources). I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.