I have implemented an custom list view with base adapter that contains focusable item like button. so i have disabled the focusable and clickable in xml. My problem is , added context menu for list item in list view using register for context menu. how to make the list view respond for both long item click and also for button list item click?
Get reference to the button and then assign onclicklistener to it and also assign onlongitemclick listener to listview.hope this helps
Related
this is the code.I have the list view with buttons , I am disabling item in list view in base adapter .after disabling the item in the list view the list is not refreshing. can any one know how to refresh the disable item in base adapter . now i need to change the list list view with disable item in list view. any suggestions please.
}
The View object enabled/disabled does nothing. Try to change color of the item and make a custom "disabled" flag. In onLongClick set the "disabled" flag to true and change the way it is processed after that, i.e. clicking on disabled item does nothing.
I have added a separator for a list view for giving background for linearlayout in row.xml. I have implemented onitem click for a list view row. I am displaying a dialog for onitemclick for list view Row. If the user clicks that layout background or separator Onitem click is triggering. How do I avoid this?
Thanks
I disable the click listener for layout
The problem:
I have a ListView item with a relatively complex layout. One of the children in the list item view is a TextView with links. The TextView can handle the clicks on links found in it(by using Linkify), and has a OnClickListener that handles click on parts of the text that are not links. The listener will just get the position of the view in the ListView and perform a click:
#Override
public void onClick(View v) {
int position = mListView.getPositionForView(v);
mListView.performItemClick(v, position, mAdapter.getItemId(position));
}
Everything works fine, except the click doesn't trigger the ListView to update the list item's drawable state. It does trigger that when you click on other TextViews in the item that are not clickable.
Thanks!
Got it working.
Set the list item view clickable and set its background as a state-list drawable, also set addStatesFromChildren to true. This will make sure the state of the list view item is changed when any of its children is clicked(assume the child is clickable).
However, this will cause the ListView itself not receiving focus, so you need to handle the click by adding View.OnClickListener to the list item itself instead of adding a OnItemClickedListener to the ListView.
I have used a button in all list items of a listview. I lost the list item click when i added a clickable componenet is list items of the list view. Now i need to add a button in listitems in of the listview and i added it. I need to have click event for both list items and also the buttons. How can i make is possible.
Please share.
Thanks in advance.
You'll have to attach click listeners to the internal views. Try to create a listener for each ViewHolder and recycle them just like you do for the views passed in to getView(). Note that you'll also have to attach a long click listener or explicitly disable long clicks on the new clickable subview or you will lose the context menu on the list item. Another thing to think about is how you intend to handle d-pad navigation with these sub-views.
I've a listview where each listitem has a checkbox. When I click list item, OnItemClick is called but checkbox is also clicked, that's annoying coz checbox onclick actions are triggered.
Edit:
how can I prevent checkbox from being clicked when row Item is clicked?
UPD:
Try to add to root view of the listitem layout this attribute android:descendantFocusability="blocksDescendants".
This should work