I'm using a ListView to show some images and names in my application. I can make the ListView tiles clickable and start new activities as well . But now i want to do different actions for the different items that are on one listview tile. If user clicks on image, image opens and the textView will show some toast or something. The ImageView and TextView are on the same ListView Tile. How can i achieve this? Any Help?
3 Answers
Define OnClickListener events in your adapter for the button and textview as required and you are done. They will precede the click event for the list item by default.
if the contained views in your custom row layout does not have a click event it will fall back to the click event of the list view item.
7 Comments
You can implement click event in adapter, but you also implement it in activity. You can find solution in :http://www.migapro.com/click-events-listview-gridview/
hope it can help you. Some note: should not use view holder in gridview like above tuturial, it can make some bug, can implement direct like this:
button1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
((ListView) parent).performItemClick(v, position, 0); // Let the event be handled in onItemClick()
}
});
Comments
Another way to implement this elegantly is to add secondary views called 'accessories' to the item views associated with your ListView. This is explaned quite well in the link below by Cyril Mottier: A Google Developer Expert on the Android platform:
http://cyrilmottier.com/2011/11/23/listview-tips-tricks-4-add-several-clickable-areas/