如何在galery android?
等上下文操作栏上添加微调器现在我可以设置像#34; 1选择" " 2选择"
这是我的代码
public void lvMainOnLongItemClick(){
lvMain.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
lvMain.setMultiChoiceModeListener(new MultiChoiceModeListener() {
private int nr = 0;
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
// TODO Auto-generated method stub
return false;
}
@Override
public void onDestroyActionMode(ActionMode mode) {
// TODO Auto-generated method stub
adapter.clearSelection();
}
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
// TODO Auto-generated method stub
nr = 0;
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.canvas_main, menu);
menuEdit = menu.findItem(R.id.menu_edit);
menuUpload = menu.findItem(R.id.menu_upload);
menuUpload.setVisible(false);
return true;
}
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
// TODO Auto-generated method stub
switch (item.getItemId()) {
case R.id.menu_edit:
Toast.makeText(rbkMain.this, "Edit", Toast.LENGTH_SHORT).show();
break;
case R.id.menu_cancel:
Toast.makeText(rbkMain.this, "Cancel", Toast.LENGTH_SHORT).show();
break;
case R.id.menu_copy:
Toast.makeText(rbkMain.this, "Copy", Toast.LENGTH_SHORT).show();
break;
case R.id.menu_upload:
Toast.makeText(rbkMain.this, "Upload", Toast.LENGTH_SHORT).show();
break;
default:
Toast.makeText(rbkMain.this, "Yihaa", Toast.LENGTH_SHORT).show();
break;
}
return true;
}
@Override
public void onItemCheckedStateChanged(ActionMode mode, int position,long id, boolean checked) {
// TODO Auto-generated method stub
if (checked) {
nr++;
adapter.setNewSelection(position, checked);
} else {
nr--;
adapter.removeSelection(position);
}
if(nr > 1)
menuEdit.setVisible(false);
else
menuEdit.setVisible(true);
mode.setTitle(nr + " selected");
}
});
lvMain.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view,int position, long id) {
lvMain.setItemChecked(position, adapter.isPositionChecked(position));
return false;
}
});
很高兴为你提供帮助......快乐的编码
答案 0 :(得分:1)
对于常规ActionBar,这对我Adding spinner to ActionBar (not Navigation起作用,但对于上下文操作栏,它无效。这就是我如何使它工作,看它是否可以帮助你。
对于你的listview听众来说:
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
mode.getMenuInflater().inflate(YOUR_MENU_XML, menu);
filterSpinner = (Spinner) MenuItemCompat.getActionView(menu.findItem(R.id.menu_overlay_spinner));
filterSpinner.setAdapter(send2Adapter);
return true;
}
菜单xml应该是这样的:
<item
android:icon="@drawable/filter"
android:id="@+id/menu_overlay_spinner"
android:title="Spinner"
app:actionViewClass="android.widget.Spinner"
app:showAsAction="ifRoom"
android:actionLayout="@layout/YOUR_ACTION_LAYOUT"/>
最后,actionLayout只是一个以Spinner为根的布局:
<?xml version="1.0" encoding="utf-8"?>
<Spinner xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
答案 1 :(得分:0)
on onCreate of main activity
// This has to be called before setContentView and you must use the
// class in android.support.v4.view and NOT android.view
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
显示/隐藏操作栏中的进度。注意使用actionbarsherlock你必须使用boolean.TRUE / FALSE,而不仅仅是true / false .........
if (getSupportLoaderManager().hasRunningLoaders()) {
setProgressBarIndeterminateVisibility(Boolean.TRUE);
} else {
setProgressBarIndeterminateVisibility(Boolean.FALSE);
}