How to change the Menu of my gallery app on Longclick of an Image? I have studied all these links Link for Menu
This link is about Menu for changing the Menu options Onprepareoptionsmenu
public class PictureHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
public ImageView pictureThumbnail;
public PictureHolder(View itemView) {
super(itemView);
itemView.setOnClickListener(this);
itemView.setOnLongClickListener(this);
this.pictureThumbnail = (ImageView) itemView.findViewById(R.id.pictureThumbnail);
}
@Override
public boolean onLongClick(View view) {
GalleryBrowserActivity.a=0;
// g.tRY();
Log.d("hi","hello Image");
return true;
}
@Override
public void onClick(View v) {
Context context = v.getContext();
Intent intent = new Intent(context, PictureDetailActivity.class);
Picture picture = (Picture) galleryList.get(getAdapterPosition());
intent.putExtra(AppConstants.PICTURE_PATH, picture.getPath());
Activity activity = (Activity) context;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(activity, v, AppConstants.PICTURE_ANIMATION);
context.startActivity(intent, options.toBundle());
} else {
context.startActivity(intent);
}
}
The other class is: This is the class in which i am defining Menu
public boolean onCreateOptionsMenu(Menu menu) {
if(a==1)
getMenuInflater().inflate(R.menu.menu_gallery_browser, menu);
if(a==0)
getMenuInflater().inflate(R.menu.picture_longclick, menu);
return true;
}