Sunday , November 28 2021

Create Options Menu for RecyclerView Item Tutorial – Android Coding by DMTechnolab

The package The trap.Simplified coding.recyclerviewoptionsmenu;

Import Android.Content.Context;

Import Android.Content.Dialog interface;

Import Android.Support.v7.App.AlertDialog;

Import Android.Support.v7.Widget.Flash list;

Import Android.Support.v7.Widget.RecyclerView;

Import Android.Opinion.Layout;

Import Android.Opinion.menu item;

Import Android.Opinion.Opinion;

Import Android.Opinion.Viewgroup;

Import Android.Widget.text view;

Import Java.Useful.The list;

/ **

* Created by Belal on 29/09/16.

* /

public class CustomAdapter Is spread RecyclerView.Adapter<CustomAdapter.View folder> {{

Private The list The list;

Private Context mCtx;

public CustomAdapter()The list The list, Context mCtx) {{

this.The list = The list;

this.mCtx = mCtx;

}

@Override

public View folder onCreateViewHolder()Viewgroup Parent, int View) {{

Opinion v = Layout.From()Parent.getContext()))

.To inflate()R.Layout.Baggage catalog, Parent, false);

The return New View folder()v);

}

@Override

public Zero onBindViewHolder()The last CustomAdapter.View folder The holder, int Post) {{

My list My list = The list.get()Post);

The holder.textViewHead.Settext()My list.Gatehead()));

The holder.textViewDesc.Settext()My list.Getdesk()));

The holder.Button view.setOnClickListener()New Opinion.OnClickListener()) {{

@ Override

public Zero on click()Opinion Opinion) {{

// create a popup menu

Flash list Pop up = New Flash list()mCtx, The holder.Button view);

// xml resource moving menu

Pop up.To inflate()R.Menu.Option_menu);

// add click listener

Pop up.setOnMenuItemClickListener()New Flash list.Onmenuytem Klicksteiner()) {{

@Override

public Boolean click onMenuItem()menu item item) {{

to switch ()item.getItemId())) {{

matter R.Id.Menu 1:

// click handle menu 1

break;

matter R.Id.Menu 2:

// click handle menu 2

break;

matter R.Id.Menu 3:

// click handle menu 3

break;

}

The return false;

}

});

// displaying popup

Pop up.Display());

}

});

}

@Override

public int getItemCount()) {{

The return The list.Shape());

}

public class View folder Is spread RecyclerView.View folder {{

public text view textViewHead;

public text view textViewDesc;

public text view Button view;

public View folder()Opinion Item view) {{

Super()itemView);

textViewHead = ()text view) Item view.findViewById()R.Id.textViewHead);

textViewDesc = ()text view) Item view.findViewById()R.Id.textViewDesc);

Button view = ()text view) Item view.findViewById()R.Id.textViewOptions);

}

}

}


Source link

About dmtechnolab

Check Also

Simplified Coding

Android Espresso Tutorial – Testing Fragment in Isolation – Android Coding by DMTechnolab

Welcome to another tutorial in the Android test series. And this post is called Android …

Leave a Reply

Your email address will not be published. Required fields are marked *