0

I have custom list of two text views having different text string. These are items in the list. In current scenerio I can only register the setOnItemClickListener for the list. This is triggered when the item in the list is clicked. If I click on the other portion of the row, no event is generated..

How can I have the item click as well as the row click event all together, so that wherever I click on the row of the list an event is triggered.

  • 1
    You need to click cell of listView or textview independently ? – Piyush Aug 31 '17 at 10:55
  • add click listener for main layout as well as text/button that you want to click and check click on onClick(View v) method what is clicked using layout id – J Ramesh Aug 31 '17 at 10:59
  • @Piyush - Wherever I click whether it be the textview or the cell of listview, I need to call a single function. Currently I can register only the setOnItemClickListener event, which means only if i click on any of the textview do I get the event. – Adnan Karbelkar Sep 05 '17 at 06:26
  • @J Ramesh - I did that but can't register the onClick event for list as well as items in list... – Adnan Karbelkar Sep 05 '17 at 06:27

1 Answers1

1

You can achieve this by implementing callback Interface.

Implement onClickListener for a particular view and use callback listener to get the callback to you fragment or activity.

Bhuvanesh BS
  • 13,474
  • 12
  • 40
  • 66
  • I have already implemented the callback register which works fine when an Item is clicked. I need to register callback on item click of a list as well as row click of a list. – Adnan Karbelkar Sep 05 '17 at 06:30
  • ListView itemsListView = (ListView)findViewById(R.id.list_view_items); RoomsListAdapter adapter = new RoomsListAdapter(this, generateItemsList()); itemsListView.setAdapter(adapter); itemsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView> parent, View view, int position, long id) { String item = ((TextView)view).getText().toString(); Log.d(TAG,item); Log.d(TAG,"Item Clicked"); } }); – Adnan Karbelkar Sep 05 '17 at 06:33