Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Click is not working on the Listitem Listview android

I implemented the android listview with the ListActivity. Here I have the problem that when i click on the list item no action is performed when the flash color is also not coming that is the orange color. So do you have any idea about this kindly answer to my question.

@Override protected void onListItemClick(ListView l, View v, int position, long id)  {     super.onListItemClick(l, v, position, id);     Toast.makeText(getApplicationContext(), "msg msg", Toast.LENGTH_SHORT)             .show();  } 

I put this code also into the Main ListActivity.

like image 447
Rajesh Rajaram Avatar asked Jul 23 '12 09:07

Rajesh Rajaram


2 Answers

The first thing what you have to note here is, whenever there are Clickable elements like Buttons or ImageButtons present in your ListView element, they take the control of click events. And so your ListView won't get the chance to accept the click event.

What you simply have to do is, set the focusable attribute to false for the Button or ImageButton you have in your ListView. But still they will work without any problem and also your ListView's onListItemClick will also work.

Try this,

        <Button  android:id="@+id/textsize_increaser"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_toRightOf="@+id/back_button"         android:focusable="false"         android:text=" A + "/> 

Here I have added this android:focusable="false" and it works fine. try it.

like image 139
Andro Selva Avatar answered Oct 03 '22 05:10

Andro Selva


Have you set the choice mode of ListView to SINGLE :

     listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); 

And if you have any clickable imageview or textview or button in the list item, then make them not focusable (in your Adapter class):

        yourButton.setFocusable(false);         yourButton.setFocusableInTouchMode(false); 
like image 36
Yogesh Somani Avatar answered Oct 03 '22 06:10

Yogesh Somani