In portrait mode I have one Fragment List View (A).  When I click on the 
item it launches a new activity which in turn loads a new fragment (B) to 
display the selected record.  When I 'LongHold' on one item in (A) the CAB 
launches where I then 'Single Click' on lines to add/subtract lines to the 
'Number of Selected' and have an option to delete.  All is good in this 
mode.

In landscape mode I have something similar working except the 'B' fragment 
is launched in its own Frame so it appears alongside the list fragment (A).

The problem I am having is trying to 'highlight' the item I picked from the 
list (A) for the details being displayed (B).

    public void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    mListener.displayMarkers(id);
                getListView().setItemChecked(position, true);
    }

As soon as I setItemChecked the Contextual action bar launches.  I only 
want the Contextual action bar to launch on the initial 'long click' same 
as it does in portrait mode.

I checked how Google are doing this and in GMAIL inbox landscape on a 
tablet, single click highlights the item in the list and displays the email 
in the detail 'frame'. a 'long click' launches the CAB for the line you 
selected. You can continue to single click on lines to see the details but 
you 'long click' to add items to the CAB.  Interestingly the cell 
background is different based on whether it is selected or long clicked in 
the CAB.

The contextual action bar is configured as follows

    getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
    getListView().setMultiChoiceModeListener(multiChoiceModeListener);

The code for the multiCoiceModeListener is as follows

MultiChoiceModeListener multiChoiceModeListener = new 
MultiChoiceModeListener() {

@Override
public void onItemCheckedStateChanged(ActionMode mode, int position,
long id, boolean checked) {
mListener.removeFragmentWhenCABStarted();
if (checked) {
++mNumberOfSelectedItems;
} else {
--mNumberOfSelectedItems;
}
// Refresh the menu - Edit is only available when one item is
// selected
mode.invalidate();
mode.setTitle(String.valueOf(mNumberOfSelectedItems) + " selected");
}

@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
// Respond to clicks on the actions in the CAB
switch (item.getItemId()) {
case R.id.menu_delete:
confirmDelete();
return true;
case R.id.menu_edit:
edit();
return true;
default:
return false;
}
}

@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
// Inflate the menu for the CAB
MenuInflater inflater = mode.getMenuInflater();
inflater.inflate(R.menu.main_fragment_context_menu, menu);
mode.setTitle(String.valueOf(mNumberOfSelectedItems) + " selected");
mActionMode = mode;
return true;
}

@Override
public void onDestroyActionMode(ActionMode mode) {
mNumberOfSelectedItems = 0;
}

@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
menu.findItem(R.id.menu_delete).setVisible(true);
menu.findItem(R.id.menu_edit).setVisible(true);
if (mNumberOfSelectedItems > 1) {
menu.findItem(R.id.menu_edit).setVisible(false);
}
return true;
}
};



So to the questions.

1. How would you control the CAB based on Long Holds the way Google are 
doing it?
2. How can I select a line (or change its background) without launching the 
CAB?
3. Am I over thinking this and you have a much easier solution

Any assistance would be appreciated.

Thanks,

Jim

 

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to