我正在尝试通过ActionMode在ActionBar中显示一个菜单项,但是ActionMode和菜单项都没有显示。
在ProvasActivity上创建ListView的LongClickListener。
this.listView.setLongClickable(true);
this.listView.setOnItemLongClickListener(new OnItemLongClickListener() {
public boolean onItemLongClick(AdapterView<?> parent, View view,
int position, long id) {
Log.d(null, "ListView Pressionado");
// O action mode está ativado no momento?
if (mActionMode != null) {
// Cancela o evento
return false;
}
selectedItem = position;
mActionMode = ProvasActivity.this
.startActionMode(mActionModeCallback);
view.setSelected(true);
return true;
}
});
private ActionMode.Callback mActionModeCallback = new ActionMode.Callback() {
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
// Infla o recurso do menu a ser exibido
MenuInflater inflater = mode.getMenuInflater();
inflater.inflate( R.menu.linha_selecionada, menu );
Log.d(null, "Menu Inflado");
return false;
}
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
switch (item.getItemId()) {
case R.id.action_remover:
show();
// Fecha a Action quando executada
mode.finish();
break;
default:
break;
}
return false;
}
@Override
public void onDestroyActionMode(ActionMode mode) {
// Anula o ActionMode
mActionMode = null;
selectedItem = -1;
}
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return false;
}
private void show() {
Toast.makeText(ProvasActivity.this,
"show", Constants.TEMPO_TOAST).show();
Log.d(null, "show()");
}
};
我的菜单显示ActionMode项目(layout / menu / linha_selecionada):
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/action_remover"
android:orderInCategory="100"
android:showAsAction="never"
android:title="@string/amazenadas"/>
</menu>
我的ProvasActivity视图(layout / provas_armazenadas.xml):
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/white"
android:orientation="vertical"
android:paddingTop="50dp" >
<ListView
android:id="@+id/listview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/white"
android:dividerHeight="4px"/>
</RelativeLayout>
我正在尝试使用Vogella教程。
http://www.vogella.com/tutorials/AndroidListView/article.html
答案 0 :(得分:6)
您正在false
中返回ActionMode.Callback.onCreateActionMode
。
<强>返回强>
如果应创建操作模式,则为true;如果进入此模式,则为false 应该中止