我正在制作一个可以选择/取消选择图像的应用程序。 ,当我选择所有图像一次
GridView.getCheckedItemPositions()
会返回正确的值。但如果我取消选择任何项目,此方法不会返回更新的值。
这是我的代码。
gridView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View view, int position,
long id) {
//Toast.makeText(GalleryImages.this, "position"+position, Toast.LENGTH_SHORT).show();
ActionMode mode =startActionMode(mActionModeCallback);
mode.setTitle(gridView.getCheckedItemCount() + " Selected");
Toast.makeText(GalleryImages.this, ""+gridView.getCheckedItemPositions().size(), Toast.LENGTH_SHORT).show();
}
});
final ActionMode.Callback mActionModeCallback = new ActionMode.Callback() {
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
// TODO Auto-generated method stub
return false;
}
@Override
public void onDestroyActionMode(ActionMode mode) {
mode=null;
}
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
// TODO Auto-generated method stub
getMenuInflater().inflate(R.menu.contextual_menu, menu);
return true;
}
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
layoutForAlertDialog = (LayoutInflater) GalleryImages.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = layoutForAlertDialog.inflate(R.layout.addtag_dialog, null);
alertForTag = new AlertDialog.Builder(GalleryImages.this);
alertForTag.setTitle("Enter Name Tag");
alertForTag.setView(view);
alertForTag.create();
alertForTag.setCancelable(false).setPositiveButton("OK", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
alertForTag.show();
return true;
}
};