user1190451
user1190451

Reputation:

check boxes in listview not working

I am using listview in which each item (of list view) has a checkbox and a textview. when i am clivking on listview thw listener doesn't executes.

here is the code.

   ListView lv = (ListView) findViewById(R.id.list);

    final CustomListArrayAdaptor aa = new CustomListArrayAdaptor(this,data1);
    lv.setAdapter(aa);

    lv.setOnItemClickListener(new OnItemClickListener()
    {

        public void onItemClick(AdapterView<?> arg0, View v,int position, long arg3)
        {
            TextView tv=(TextView)v.findViewById(R.id.text);

            String s=tv.getText().toString();
            Toast.makeText(getApplicationContext(), "Item Selected :"+s,Toast.LENGTH_LONG).show();

        }
     });

It doesnt show the toast "Item Selected" when clicked on any item.

Upvotes: 1

Views: 217

Answers (2)

Om Narain Shukla
Om Narain Shukla

Reputation: 371

This part of your code is correct. Upload the other files code also. As much I know this could be the problem of focus.Add (android:focusable="false") if you are defining the check box in xml file or for the java code use the method myCheckBox.setFocusable(false).

Upvotes: 1

Avi Kumar
Avi Kumar

Reputation: 4433

As explained here

Android custom ListView unable to click on items,

the click listener only works if no other view is focusable. Setting your CheckBox to focusable="false" should do the trick for you

Upvotes: 0

Related Questions