Skip to content Skip to sidebar Skip to footer

Why Does Isitemchecked() Return True When In Actionmode?

I've set up an ActionMode callback for use as the contextual ActionBar (CAB) within an ActionBarSherlock using project. I'm trying to set up multiple select so that I can delete mu

Solution 1:

So what has worked for me is to just use

   habitListView.setOnItemClickListener(newOnItemClickListener(){

        @OverridepublicvoidonItemClick(AdapterView<?> parent, View view,
                int position, long id) {

            //handle differently when CAB is on.if (mMode != null){

                view.setSelected(!view.isSelected());

                updateCABtitle();

                //turn CAB off if this is the last to be uncheckedif (habitListView.getCheckedItemIds().length == 0){
                        mMode.finish();
                    } 

            } else {
                //start detail/edit view activityIntentintent=newIntent(getApplicationContext(), HabitDetailActivity.class);
                startActivity(intent);

            }

        }

    });

and

privateclassMyOnItemLongClickListenerimplementsOnItemLongClickListener{

    @OverridepublicbooleanonItemLongClick(AdapterView<?> parent, View view,
                    int position, long id) {


            habitListView.setItemChecked(position, true);

            mMode = startActionMode(newMyActionModeCallback());
            updateCABtitle();

            returntrue;
    }

}

I don't really understand why setItemChecked() is not working for onItemClick() but seems to be for onItemLongClick(). It looks as though there is a default click handler that gets called in AbsListView.PerformItemClick() that must do some toggling of checked/unchecked or something.

Post a Comment for "Why Does Isitemchecked() Return True When In Actionmode?"