Android List view layout Similar to Google play -
i want implement list layout similar google play have menu every individual row. please me create this.
do need create popup menu or there option available achieve this.
thanks
looks trying way in image shown. giving example of how trying achieve this.
here's how doing this. not difficult. straight implementation of popup menu.
step 1 : adapter
public class listadapter extends baseadapter{ private arraylist<string> mainlist; public listadapter(context applicationcontext, arraylist<string> questionforslidermenu) { super(); this.mainlist = questionforslidermenu; } public listadapter() { super(); this.mainlist = questionforslidermenu; } @override public int getcount() { return mainlist.size(); } @override public object getitem(int position) { return mainlist.get(position); } @override public long getitemid(int position) { return position; } @override public view getview(final int position, view convertview, viewgroup parent) { if (convertview == null) { layoutinflater inflater = (layoutinflater) getapplicationcontext() .getsystemservice(context.layout_inflater_service); convertview = inflater.inflate(r.layout.custom_row_stack, null); } textview tv1 = (textview) convertview .findviewbyid(r.id.row_textview1); textview tv2 = (textview) convertview .findviewbyid(r.id.row_install_textview1); imageview imageicon = (imageview) convertview .findviewbyid(r.id.row_imageview1); imageview imageclick = (imageview) convertview .findviewbyid(r.id.row_click_imageview1); try { tv1.settext(" list item "+ " : " + position); imageclick.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { switch (v.getid()) { case r.id.row_click_imageview1: popupmenu popup = new popupmenu(getapplicationcontext(), v); popup.getmenuinflater().inflate(r.menu.clipboard_popup, popup.getmenu()); popup.show(); popup.setonmenuitemclicklistener(new popupmenu.onmenuitemclicklistener() { @override public boolean onmenuitemclick(menuitem item) { switch (item.getitemid()) { case r.id.install: //or other code want put here.. example. toast.maketext(getapplicationcontext(), " install clicked @ position " + " : " + position, toast.length_long).show(); break; case r.id.addtowishlist: toast.maketext(getapplicationcontext(), "add wish list clicked @ position " + " : " + position, toast.length_long).show(); break; default: break; } return true; } }); break; default: break; } } }); } catch (exception e) { e.printstacktrace(); } return convertview; } }
step 2 : in activity, setting adapter:
public class customlistactivity extends activity { string[] numbers = { "ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "jack", "queen", "king" }; arraylist<string> questionforslidermenu = new arraylist<string>(); @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.listview_layout); listview listview = (listview) findviewbyid(r.id.customlistview1); (string s : numbers) { questionforslidermenu.add(s); } listadapter madapter = new listadapter(this, questionforslidermenu); listview.setadapter(madapter); }
step 3: custom row items/layout:
custom_row_stack.xml
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <imageview android:id="@+id/row_imageview1" android:layout_width="50dp" android:layout_height="50dp" android:layout_margintop="10dp" android:src="@drawable/page1" /> <textview android:id="@+id/row_textview1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginleft="10dp" android:layout_margintop="20dp" android:text="some item" android:textappearance="?android:attr/textappearancelarge" android:textcolor="#333333" /> <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <imageview android:id="@+id/row_click_imageview1" android:layout_width="50dp" android:layout_height="50dp" android:layout_gravity="right" android:clickable="true" android:src="@drawable/dots" /> <textview android:id="@+id/row_install_textview1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right" android:padding="10dp" android:text="install" android:textappearance="?android:attr/textappearancesmall" android:textcolor="#333333" /> </linearlayout> </linearlayout>
step 4 : popup menu.xml
<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android" > <item android:id="@+id/install" android:title="install" /> <item android:id="@+id/addtowishlist" android:title="add wishlist" /> </menu>
finally: screenshot of how looks like.
listview http://imageshack.com/a/img822/4144/umdy.png listview http://imageshack.com/a/img32/9839/ne90.png listview http://imageshack.com/a/img198/7404/prqc.png
if there's better solution, helpful me too. hope helps..:)
Comments
Post a Comment