I am using a custom ListView
with RatingBar
and ImageButton
. Here is my problem: When I click on my ListView
, my OnItemClickListener
is not working. Please can any one help me. Code:
ListView lv = getListView(); setContentView(lv); lv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) { Toast.makeText(SuggestionActivity.this, "" + position, Toast.LENGTH_SHORT).show(); } });
This example demonstrates how do I handle the click event in ListView in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.
AdapterView is a ViewGroup that displays items loaded into an adapter. The most common type of adapter comes from an array-based data source.
Though a very old question, but I am still posting an answer to it so that it may help some one. If you are using any layout inside the list view then use ...
android:descendantFocusability="blocksDescendants"
... on the first parent layout inside the list. This works as magic the click will not be consumed by any element inside the list but will directly go to the list item.
I have an Activity that extends ListActivity.
I tried doing something like this in onCreate:
ListView listView = getListView(); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Log.i("Hello!", "Y u no see me?"); } });
But that didn't work.
Instead I simply needed to override onListItemClick:
@Override protected void onListItemClick(ListView l, View v, int position, long id) { Log.i("Hello!", "Clicked! YAY!"); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With