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 8353273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:12:27+00:00 2026-06-09T09:12:27+00:00

I have 1 ListView and two ArrayAdapters Depending on an if statement, this will

  • 0

I have 1 ListView and two ArrayAdapters

Depending on an if statement, this will happen

listView1.setAdapter(adapter1);
or
listView1.setAdapter(adapter2);

On onCreate(), this is called,
listView1.setAdapter(adapter1);

So listView1.setOnItemClickListener() is connected to adapter 1.

During program execution when listView1.setAdapter(adapter2); is called, the ListView is updated and the display shows the appropriate results, however, clicking an item with the adapter2 results is actually still referencing the adapter1 results.

How do I get the onItemClickListener to switch when listView1’s adapters change?

Thanks

        listView1.setOnItemClickListener(new OnItemClickListener() {

        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {


            Intent i = new Intent("com.project.DetailView");
            i.putExtra("serial", list.get(position).getSerial());
            i.putExtra("name", list.get(position).getName());

            startActivity(i);

        }
    });

}


adapter1 = new ArrayAdapter<Object>(this, android.R.layout.simple_list_item_1, list1);

adapter2 = new ArrayAdapter<Object>(this, android.R.layout.simple_list_item_1, list2);
  • 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-06-09T09:12:28+00:00Added an answer on June 9, 2026 at 9:12 am

    this code may help u.

    listView.setOnItemClickListener(new OnItemClickListener() {
    
                public void onItemClick(AdapterView<?> arg0, View arg1, int position,
                        long id) {
                    // TODO Auto-generated method stub
                    Log.i("item",""+listView.getItemAtPosition(position));
    
                }
            });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two activities with ListView. This two activitises have individual layout-file. First have
I have a custom ListView with two button and I when I click either
I have ListView that uses a GridView to display several columns of data. Two
I have a ListView with ViewStyle = vsReport and two popup menus: Column popup
I have a listview with several items that are created dynamically, each has two
Here's my aproach: I have a custom ListView containing a custom Adapter containing two
I have two ItemsControls, one a ListView, and one a custom control I am
I have two views in my ViewFlipper . One of views contains a ListView
If I have two activities in my app, one with listview and the other
I have Process objects that are monitored from two different views. A Windows.Forms.ListView (actually

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.