1

私はフラグメントにこれを持っています

    @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。チェック済みとしてマークされ、背景を変更するコードが実行されますが、効果はありません。次に選択された項目が強調表示されます。何か案は?

4

0 に答える 0