我的片段中有这个
@Override
public void onActivityCreated(Bundle savedInstanceState) {
getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
getListView().setMultiChoiceModeListener(new PlayerMultiChoiceListener(getListView(), getBaseActivity()));
...
}
这就是实现
public abstract class PlayerMultiChoiceListener implements MultiChoiceModeListener {
protected final ListView listView;
protected final BaseActivity activity;
protected final PlayerManager playerManager;
public AbstractMultiChoiceListener(ListView listView, BaseActivity activity) {
this.listView = listView;
this.activity = activity;
this.playerManager = PlayerManager.getInstance(activity);
}
...
@Override
public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
mode.setTitle(listView.getCheckedItemCount() + activity.getString(R.string.action_mode_title_selected));
mode.getMenu().clear();
if (listView.getCheckedItemCount() > 1) {
mode.getMenuInflater().inflate(R.menu.list_actionmode, mode.getMenu());
} else {
mode.getMenuInflater().inflate(R.menu.list_actionmode_one_selected, mode.getMenu());
}
listView.getChildAt(position).setBackgroundResource(
checked ? android.R.color.holo_blue_light : android.R.color.transparent);
}
}
第一个选择的项目(我长按进入 ActionMode 的那个)没有被holo_blue_light
. 它被标记为选中,并且更改背景的代码被执行但没有任何效果。下一个选定的项目被突出显示就好了。有任何想法吗?