I want to keep a ImageButton with a state-list drawable in a "Wait-for-Action-Finished" state as long the action was not done.
I've seen the other topics around this problem. But in my case the other solutions are not working for me because:
It's not important that the "Wait-for-Action-Finished" drawable was shown in the RemoteView (but it would be nice...), but I don't want to duplicate the layout. It's okay if the Wait-State was shown in the RecyclerView items only. But there it should work along with the Multiselector function.
I'm using an ImageButton because it can be disabled in a RemoteView (in opposite to Button/ToggleButton/CompoundButton in general).
any hints how I could solve this?
I've got it working by combining the selected and activated states.
My button looks like this:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/progress_small" android:state_activated="true" android:state_selected="true"/>
<item android:drawable="@drawable/btn_bookmark_add_pressed" android:state_focused="true" android:state_pressed="true" />
<item android:drawable="@drawable/btn_bookmark_add_pressed" android:state_focused="false" android:state_pressed="true" />
<item android:drawable="@drawable/btn_bookmark_add_pressed" android:state_focused="true" />
<item android:drawable="@drawable/btn_bookmark_add_normal" android:state_focused="false" android:state_pressed="false" />
</selector>
And my button.onClicklistener looks like this:
public void onClick(View v) {
if (v.isActivated() && v.isSelected()) {
return;
}
v.setActivated(true);
v.setSelected(true);
AppController.getJobManager().addJob(new Job()));
}
This way it won't collide neither with "click the itemView", where selected state will be propagated to all child views (inclusive my buttons) nor with activate the "multi-selection" feature where the activated state will be propagated to all child views.
After the job is finished it will notify (EventBus) the RecyclerView
where the ViewHolder
can reset both activated and selected state back to false.