Closed kojofosu closed 4 years ago
Today there is no API to remove the selection only to set a new one.
The second parameter on setItemSelected
is to propagate or not the change to the listeners.
/**
* Remove the selected state from the current item and set the selected state to true
* for the menu item with the [id]
*
* @param id menu item id
* @param dispatchAction enable this action to dispatch listener events
*/
fun setItemSelected(id: Int, dispatchAction: Boolean = true)
Tell me more about your use case. You want to remove the current selection and leave the menu without any active items?
Yes, i want to remove current selection and leave the menu without any active items after some seconds of selection.
So i want the items to be deselected like this....after 5 seconds like this
but then somtimes it ends up like this.. where after disabling the icon with .setItemEnabled(getSelectedItemId, false)
, the icon turns color gray first.
in case you wanted a sample code of how i'm handling it, this is it below
private void isChipItemSelected(final int getSelectedItemId) {
Log.d(TAG, "chipNavigation bar isSelected : " + getSelectedItemId );
final int interval = 2000; // 2 Seconds before the item disables
Handler handler = new Handler(); // init handler
Runnable runnable = new Runnable() {
public void run() {
final int interval = 1000; // 1 Second before the item enables again for user to be able to click
Handler handler = new Handler();
Runnable runnable = new Runnable() {
public void run() {
chipNavigationBar.setItemEnabled(getSelectedItemId, true);
}
};
handler.postAtTime(runnable, System.currentTimeMillis() + interval); //chip enabler handler
handler.postDelayed(runnable, interval);
chipNavigationBar.setItemEnabled(getSelectedItemId, false); //disabling chip item to reverse animation
Log.d(TAG, "chipNavigation bar getSelectedItemId : " + chipNavigationBar.getSelectedItemId());
}
};
handler.postAtTime(runnable, System.currentTimeMillis() + interval); //chip disabler handler
handler.postDelayed(runnable, interval);
}
Indeed, you got a very particular use case. But anyway, remove the selection sounds a very basic requirement that we should support.
I'll add this to the next release.
Closed by #36
chipNavigationBar.setItemSelected(getSelectedItemId, false)
trying to use this method to deselect a particular item . But it doesn't work