OnItemClick Listner does not work on listview?

  • Replies:4
  • OpenNot stickiedUnanswered
  • Forum posts: 1

Mar 7, 2016 11:50:20 AM via Website

listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView parent, View view, int position, long id) {
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.containerView, new ProductFragment());

  • Forum posts: 256

Mar 7, 2016 1:31:30 PM via Website

Maybe you mean:

public void onItemClick(AdapterView<?> parent, View view, int position, long id)  ?

Please, provide Logcat dump.

— modified on Mar 7, 2016 1:32:03 PM

  • Forum posts: 207

Mar 9, 2016 6:30:47 AM via Website

Implementation looks like ok now where you have put this method. If you define this in onCreate method it should work, If not working share this class code for better idea.

  • Forum posts: 5

Mar 9, 2016 7:35:22 PM via Website

Try adding breakpoint inside onItemClick and see whether listener is getting called.

  • Forum posts: 12

Mar 10, 2016 3:31:01 PM via Website

Another option might be to set the click listener directly on the views of the list view. That way you can better control which part actually handles the click (whole item or maybe just a part?). Also helpful in case the click event is handled by another view while overlays your list items...