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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:37:54+00:00 2026-06-11T01:37:54+00:00

I have made one custom ListView but it is not calling any onclick listener

  • 0

I have made one custom ListView but it is not calling any onclick listener or context menu that I have registered.

Here is my custom adapter:

class AdapterContactsActivity extends BaseAdapter {

    private Activity activity;
    private ArrayList<HashMap<String, String>> rowdata;
    private static LayoutInflater inflater = null;
    public ArrayList<String> checkedContacts = new ArrayList<String>();

    public AdapterContactsActivity(Activity a,
        ArrayList<HashMap<String, String>> d) {
        activity = a;
        rowdata = d;
        inflater = (LayoutInflater) activity
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    public int getCount() {
        return rowdata.size();
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }

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

        if (convertView == null)
             convertView = inflater.inflate(R.layout.item_listview_contacts,
                null);
         final ViewHolder holder = new ViewHolder();
         holder.txtTitle = (TextView) convertView.findViewById(R.id.textView1);
         holder.chkBox = (CheckBox) convertView.findViewById(R.id.checkBox1);
         final HashMap<String, String> row = rowdata.get(position);
         // Setting all values in listview
         holder.txtTitle.setText(row.get(EmsContactsActivity.KEY_TITLE));
         final String contact_id = row.get(EmsContactsActivity.KEY_ID);
         convertView.setTag(contact_id);
         holder.txtTitle.setTag(contact_id);
         if (checkedContacts.contains(contact_id))
             holder.chkBox.setChecked(true);
         else
             holder.chkBox.setChecked(false);
         holder.chkBox.setOnClickListener(new OnClickListener() {

         public void onClick(View v) {
             // TODO Auto-generated method stub
             if (!holder.chkBox.isChecked()
            && checkedContacts.contains(contact_id))
                 checkedContacts.remove(contact_id);
             else {
                 checkedContacts.add(contact_id);
             }
         }
    });
    return convertView;
    }
    static class ViewHolder {
        public TextView txtTitle;
        public CheckBox chkBox;
    }
}

Also my row’s item view:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linearLayout1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/black" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_toRightOf="@+id/checkBox1"
        android:padding="5dp"
        android:textAppearance="@android:style/TextAppearance.Large"
        android:textColor="@android:color/white" />

    <CheckBox
        android:id="@+id/checkBox1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:padding="5dp" />

</RelativeLayout>

Now I have added all contacts to the adapter but the on click of ListView item I can not even get logcat notification also so on click event I not called.

ListView Code :

Cursor allContacts = getAllContacts();
if (allContacts != null && allContacts.getCount() > 0) {

    txtEmptyText.setVisibility(View.GONE);
    registerForContextMenu(listViewContacts);
    listViewContacts.setVisibility(View.VISIBLE);
    listViewContacts.setFastScrollEnabled(true);
    listViewContacts.setTextFilterEnabled(true);
    listViewContacts.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
    listViewContacts.setBackgroundColor(Color.TRANSPARENT);
    searchList = new ArrayList<HashMap<String, String>>();
    searchList = getArrayListWithContacts(allContacts);

    txtTotalContacts.setText("Displaying " + allContacts.getCount()
                + " contacts");

    // Wrap your adapter within the SimpleSectionAdapter
    searchAdapter = new AdapterContactsActivity(this, searchList);
    // Set the adapter to your ListView
    listViewContacts.setAdapter(searchAdapter);

    listViewContacts.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> arg0, View v,
                    int position, long arg3) {
            // TODO Auto-generated method stub
            Log.i("CLICKED", position + " clicked");
    }
    });
} else // No Contacts Found
{
    String text = "<div>You don't have any contacts to display.<br /><br />"
            + "To add a contacts, <b>Menu</b> and touch:<br /><br />"
            + "&#8226; <b style='color:#FFFFFF;'>Accounts</b> to add or configure and account with contacts you can sync to the phone<br /><br />"
            + "&#8226; <b>New Contact</b> to create a new contact from scratch<br /><br />"
            + "&#8226; <b>Import/Export</b></div>";
    txtEmptyText.setVisibility(View.VISIBLE);
    listViewContacts.setVisibility(View.GONE);
    txtEmptyText.setText(Html.fromHtml(text));
    editSearchContacts.setEnabled(false);
}
  • 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-11T01:37:56+00:00Added an answer on June 11, 2026 at 1:37 am

    Set the focusable property on the CheckBox to false:

    <CheckBox
            android:id="@+id/checkBox1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:padding="5dp"
            android:focusable="false"  />
    

    Also, you may want to inflate the row layout like this:

    convertView = inflater.inflate(R.layout.item_listview_contacts, parent, false);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made a swings application but there is one problem in that which
So i have this listview with my custom XML file that i made for
I have made a custom object called students that has two nsstring object. One
I have made some changes in one perforce client, but haven't submitted them. I
I have made a batch file that call another one program.bat , the first
I have made a new custom EditForm.aspx in MS sharepoint on one of my
I have made a custom ArrayAdapter for a ListView, in order to customize the
I have a shopping cart ListView control backed by a custom object that has
i made one script from here but now i have problem with geting $_POST['file']
i have a custom ListView control and Custom ListViewItem that has a tri-state checkbox,

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.