简体   繁体   中英

How to select row in custom list view android?

I am new Android developer. I have a custom ListView with image, title, description. When I click row in custom list view, there is no action onclick.

Please advise how to solve this issue?

first set onItemClickListener to your listview

and then perform your action in onItemClick method.

listView.setOnItemClickListener(this);

@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { 

       //perform your action here

}
listView.setOnItemClickListener((parent, view, position, id)  {

    });

if you have Button in list_item.xml put android:descendantFocusability="blocksDescendants" in the LinearLayout or RelativeLayout you have

ListView Tips & Tricks #4: Add Several Clickable Areas

https://syedasaraahmed.wordpress.com/2012/10/03/android-onitemclicklistener-not-responding-clickable-rowitem-of-custom-listview/

First you have to add the list view like this: ListView lv and it assigns lv as the ListView constructor, becoming referenced to ListView it as you have set it.

Then Set this:

lv.setOnItemClickListener(this);

@Override public void onItemClick(AdapterView<"your adapter view goes here"> adapterView, View view, int position, long l) { //perform your action here } <

You have called on the list view method to execute the message of the setonitemclicklistener method in the list view class which as the constructor you would set up Ie list view referenced as lv. It all ties together

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM