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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:07:08+00:00 2026-06-18T04:07:08+00:00

I am creating an app that has a contacts list inside it. Currently the

  • 0

I am creating an app that has a contacts list inside it. Currently the list works and displays all of my contacts just the way i want it. However i need to add a click function to them. I want to call them once i press one of them. How can i do that? I already have an onListItemClick method in the same activity due to an rss reader. How can i filter it out? Take a look at my code:

        //Load contacts into ListView on people screen
    contactListView = (ListView) findViewById(R.id.contactsListView);
    contactstock = new ArrayList<ContactStock>();

    mCursor = managedQuery(ContactsContract.Data.CONTENT_URI, null, Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'", null,
            ContactsContract.Data.DISPLAY_NAME + " ASC");
    int number = mCursor.getColumnIndex(Phone.NUMBER);      
    int name = mCursor.getColumnIndex(ContactsContract.Data.DISPLAY_NAME);
    while (mCursor.moveToNext()) {
        String phName = mCursor.getString(name);
        String phNumber = mCursor.getString(number);
        contactstock.add(new ContactStock(phName, phNumber));
    }
    contactListView.setAdapter(new ContactListAdapter(MainActivity.this,
            contactstock));

ContactStock.java:

public class ContactStock {

    private String name;
    private String number;

    public ContactStock(String name, String number) {
        this.name = name;
       this.number = number;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setNumber(String number) {
        this.number = number;
    }

    public String getName() {
        return this.name;
    }

    public String getNumber() {
        return this.number;
    }

}

ContactListAdapter.java:

public class ContactListAdapter extends ArrayAdapter {
private final Activity activity;
private final List stocks;

public ContactListAdapter(Activity activity, List objects) {
    super(activity, R.layout.listview_detail_tab_contact_list, objects);
    this.activity = activity;
    this.stocks = objects;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {

    View rowView = convertView;
    ContactStockView sv = null;
    if (rowView == null) {
        // Get a new instance of the row layout view
        LayoutInflater inflater = activity.getLayoutInflater();
        rowView = inflater.inflate(
                R.layout.listview_detail_tab_contact_list, null);

        // Hold the view objects in an object,
        // so they don't need to be re-fetched
        sv = new ContactStockView();
        sv.name = (TextView) rowView.findViewById(R.id.contact_name);

        sv.number = (TextView) rowView.findViewById(R.id.contact_number);

        // Cache the view objects in the tag,
        // so they can be re-accessed later
        rowView.setTag(sv);
    } else {
        sv = (ContactStockView) rowView.getTag();
    }
    // Transfer the stock data from the data object
    // to the view objects
    ContactStock currentStock = (ContactStock) stocks.get(position);
    sv.name.setText(currentStock.getName());
    sv.number.setText(currentStock.getNumber());

    // TODO Auto-generated method stub
    return rowView;
}

protected static class ContactStockView {
    protected TextView name;
    protected TextView number;
}
}

My current listview code(for rss viewer):

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    Uri uri = Uri.parse(links.get(position).toString());
    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    startActivity(intent);
}

ListView row xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >


<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="5dp"
    android:src="@drawable/defaultavatar" />

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >


    <TextView
        android:id="@+id/contact_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="5dp"
        android:text="Who am I"
        android:textAppearance="?android:attr/textAppearanceLarge" />


    <TextView
        android:id="@+id/contact_number"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:text="000000000" />

</LinearLayout> 

</LinearLayout>

I got the phone number from the contact i tapped by using this code:

contactstock.get(arg2).getNumber()
  • 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-18T04:07:09+00:00Added an answer on June 18, 2026 at 4:07 am

    You should set both listviews and set onItemClickListener for each one.

    ListView l1 = (ListView)findViewById(R.id.list1);
    ListView l2 = (ListView)findViewById(R.id.list2);
    
    // listener for the first one 
    l1.setOnItemClickListener(new OnItemClickListener() {
    
            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                    long arg3) {
                // TODO Auto-generated method stub
    
            }
    
        });
    
     // listener for the other
     l2.setOnItemClickListener(new OnItemClickListener() {
    
            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                    long arg3) {
                // TODO Auto-generated method stub
    
            }
    
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a web app that has a list of commands that change elements
I'm creating iOS app that has a label. I want to set two colors.
I'm creating an iPhone app that has a DB in PostgreSql. I want to
I'm creating an app that has a similar layout as the Apple Contacts app.
I am creating an app that has three tabs on the main screen. Each
I'm creating a MonoTouch app that has some declarative business logic that the client
I am creating an app that alerts user if he has been stationary for
I am creating a custom membership provider for a web app that already has
I'm creating an app that should list the date and time when a button
I'm creating an app that has a database using sqlite. On my app I've

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.