MultiChoiceModeListener causes problems with SherlockListFragment

So, I read this earlier question for ideas on how to allow me to click an item in a list to do one action or long press this item to switch to ActionMode, where I can select multiple items and use the ActionBar to do something with these elements. However, I am having problems with this answer . In particular, I implement this in a SherlockListFragment (using ActionBarSherlock). However, the moment I declare a new MultiChoiceModeListener, Eclipse throws a couple of compilation errors.

Description Resource Path Location Type Cannot override the final method from SherlockListFragment DateTimeListFragment.java /path/to/my/project line 127 Java Problem The method inflate(int, Menu) in the type MenuInflater is not applicable for the arguments (int, Menu) DateTimeListFragment.java /path/to/my/project line 125 Java Problem 

This disappears when I remove the MultiChoiceModeListener. I have no idea what could be causing this, since there is nothing strange in what I know.

 public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { //super.onCreateOptionsMenu(menu, inflater); inflater.inflate(R.menu.alarmsmenu, menu); //line 125 } public boolean onOptionsItemSelected(MenuItem Item) //line 127 { switch(Item.getItemId()) { case R.id.addAlarm: addAlarm(); return true; case R.id.editAlarms: return true; default: return super.onOptionsItemSelected(Item); } } 

I am very confused. Why does the implementation of MultiChoiceModeListener mean that I cannot override OnOptionsItemSelected?

EDIT: To clarify, here is my import.

 import java.util.Calendar; import java.util.GregorianCalendar; import android.app.DatePickerDialog; import android.app.TimePickerDialog; import android.content.DialogInterface; import android.content.Intent; import android.database.Cursor; import android.os.Bundle; import android.support.v4.app.*; import android.support.v4.content.Loader; import android.view.View; import android.view.ViewGroup; import android.widget.AbsListView.MultiChoiceModeListener; import android.widget.AdapterView; import android.widget.AdapterView.OnItemLongClickListener; import android.widget.DatePicker; import android.widget.ListView; import android.widget.TimePicker; import com.actionbarsherlock.app.SherlockListFragment; import com.actionbarsherlock.app.ActionBar; //Yes, it unused... import com.actionbarsherlock.view.*; import com.commonsware.cwac.loaderex.acl.*; 
+7
source share
3 answers

As the kind person from reddit notified me , obviously ActionBarSherlock does not currently support MultiChoiceModeListener. The fact that I use the ActionBarSherlock menu when the listener wants native Android menus probably contributed to this problem.

+6
source

If you use Eclipse, I would remove all your import directives and hit Ctrl + Shift + o ( Cmd + Shift + o for Mac), and VERY carefully choose conflict-based imports.

My current SherlockActivites, which admittedly don't use snippets:

 import com.actionbarsherlock.app.ActionBar; import com.actionbarsherlock.app.ActionBar.Tab; import com.actionbarsherlock.app.SherlockActivity; import com.actionbarsherlock.view.Menu; import com.actionbarsherlock.view.MenuItem; 

I had the exact problems you described when I converted my Activity to SherlockActivity s.

EDIT: Adding the MultiChoiceModeListener interface to my class called methods such as the following:

 public boolean onActionItemClicked( ActionMode mode, android.view.MenuItem item ) { // TODO Auto-generated method stub return false; } 

Please note that MenuItem is fully compliant. This may be the key here. Perhaps you are trying to transfer the Sherlock menu to what the Android menu expects.

I think my advice will be to try to qualify all your conflicting calls, and after you figure out which methods are being called incorrectly, from there.

For example, change:

 public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) 

To:

 public void onCreateOptionsMenu(Fully.Qualified.Path.Menu menu, MenuInflater inflater) 
+1
source

Make sure you import these two classes, not the vanilla android version:

 import com.actionbarsherlock.view.Menu; import com.actionbarsherlock.view.MenuItem; 

In addition, I would try to import the ActionBarSherlock demo project and see if the ActionItem example works there.

0
source

All Articles