ListView OnItemClickListener not responding?

I have searched everywhere for a solution for this, but I cannot figure out how to implement it. My OnItemClickListener was OnItemClickListener disabled on my ListView rows, because I have an ImageButton in the row layout that takes focus. There were numerous questions that I found, but none of them took me anywhere.

I checked this question, but I could not make heads or tails out of it. I just need a way to make the strings comfortable so I can detect when the row is pressed. Long press and focus work fine.

+44
java android listview
Mar 03 '10 at 0:17
source share
13 answers

Instead of OnItemClickListener, add OnClickListener to each of your views returned by your adapter. You will need to use the setItemsCanFocus list setting:

 ListView list = (ListView) findViewById(R.id.myList); list.setAdapter(new DoubleClickAdapter(this)); list.setItemsCanFocus(true); 

and then in your getView adapter, this will result in a clickable string. The button is supposed to be in inflated xml.

 @Override public View getView(int position, View convertView, ViewGroup parent) { View view = View.inflate(context, R.layout.cell, null); view.setClickable(true); view.setFocusable(true); view.setBackgroundResource(android.R.drawable.menuitem_background); view.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { new AlertDialog.Builder(context).setTitle("touched").show(); } }); return view; } 
+59
Mar 03 '10 at 7:01
source share

set your ImageButton attribute:

 android:focusable="false" 

Because AbsListView.onTouchEvent check child.hasFocusable() .

+51
Dec 23 '10 at 12:37
source share

I tested the following solution on SDK levels 8 and 16.

In getView()

 setFocusable(false); setClickable(false); 

instead of setting them true in the getView() adapter, it does what it seems to me to require an initial request, and means that the OnItemClickListener call OnItemClickListener called, provided that OnClickListener not set to getView() .

I assume that everything you can do in View OnClickListener can be done just as easily in ListView OnItemClickListener . ( setOnClickListener in the view implicitly sets the possibility of clickability, which prevents the ListView OnItemClickListener from being called, apparently.)

The behavior is the same as you would expect, in the form of a visual ImageButton state when you click or drag an item.

The solution is a little illusion, since the list item is not pressed by ImageButton itself, so if the button does not occupy the entire list item, clicking in another place on the item will still make the button popped state reflects the click. The same goes for focus. It may be worth the price.

+10
Sep 19 '12 at 23:02
source share

It will definitely work. Add this to your layout definition.

 android:descendantFocusability="blocksDescendants" 

Found solution here

+6
Oct 11 '13 at 19:28
source share

An alternative to setting OnClickListener for each view is to NOT use ImageButton - use ImageView instead. ImageView can still send events to OnClickListener and will not take focus.

+5
Sep 14 '10 at 21:59
source share

best way to do this:

  android:focusable="false" android:focusableInTouchMode="false" 

set these properties for this Imagebutton and try. I

+5
Apr 07 '13 at 7:04 on
source share

In my version of this problem, the problem was that I set my TextView object to android:inputType="textMultiLine" . When I deleted this line, the question that the list is not clickable disappeared. Looks like an unpleasant little mistake.

In addition, I can still use the android:minLines/android:maxLines without problems, so this is not a big problem. Just not the solution I was expecting.

+4
Jun 11 '10 at 2:25
source share

As an alternative solution that worked for me, you can try expanding your adapter from BaseAdapter (iso implementation of the ListAdapter interface)

+1
Feb 14 '12 at 18:41
source share

The following line solved the problem in my project:

 <TextView ... android:textIsSelectable="false" /> 
+1
Dec 04 '15 at 15:59
source share

Put this code ImageView nextpage= (ImageView)findViewById(R.id.btnEdit); instead of ImageButton . now the list item is active

0
Feb 03 '14 at 13:14
source share

I have subclasses of ImageButton and setFocusable="false" in the layout definition for me not working. He decided to call setFocusable(false) in the constructor of the subclass.

0
Mar 15 '14 at 2:59
source share
  listView= (ListView) findViewById(R.id.listview_names); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Toast.makeText(getBaseContext(),"Clicked Button",Toast.LENGTH_LONG).show(); Log.d("h","clicked"); /* Intent intent=new Intent(MainActivity.this,Display_data.class); intent.putExtra("NAME",n); intent.putExtra("AGE",a); startActivity(intent);*/ } }); 

Y this toast doesn't work

0
Jul 12 '17 at 7:24
source share

Using a ScrollView may prevent onItemClickListener getting input.

Hope this helps anyone.

-one
Oct 28 '14 at 17:25
source share



All Articles