Android context Menu

Source: Internet
Author: User

Package Com.bawei.d4;import Java.util.arraylist;import Java.util.list;import android.os.bundle;import Android.app.activity;import Android.content.intent;import Android.view.contextmenu;import Android.view.Menu; Import Android.view.menuitem;import Android.view.view;import Android.view.contextmenu.contextmenuinfo;import Android.widget.adapter;import Android.widget.adapterview;import Android.widget.adapterview.adaptercontextmenuinfo;import Android.widget.adapterview.onitemclicklistener;import Android.widget.baseadapter;import Android.widget.ListView;PublicClassMainactivity extends Activity {PublicStatic string[] Name=Newstring[]{"Patriot (Aigo) MP5 digital player U303 8GB touch screen MP3 White","Snow Man 2014 new Women's OL career one shoulder bag female tote crossbody bag 8305 m White","Long-sleeved dress chiffon skirt slim-fit women Europe and the United States long-run the king of the big fairy dress","Korea stationery Cute creative fashion office supplies large multifunctional storage box pen bag","ThinkPad E531 6885-d4c Celeron dual-core 500G Lenovo IBM Business Notebook PC","Cash Pack Shun Fung nokia/Nokia 107 dual SIM standby phone extra long standby","3-pack Arctic Velvet camisole Women's new style built-in black strappy modal lace vest","[Standard delivery 8G card] sony/Sony hdr-cx240e Digital camera/DV HD professional camera","Natural white blue green chalcedony crystal earrings men and women 925 black agate Earrings anti-allergic silver jewelry","2014 Korean European root yarn dress new summer girl embroidered princess puff skirt pink fake two piece set 270","Hangyi 2014 Summer New Korean version slim lady dress ladies lace chiffon fashion dress hipster","hp/HP Envy Envy 15-j105tx four generation i7 high split screen 8G memory/1t/4g single display","Casio casio fashion quartz watch mens belt watch mtp-1095q-7b","Genuine Hellokitty doll kt plush toys Hello Kitty Dolls dolls doll Tanabata birthday gift Girl","Genuine cartoon baby picture frame two-connected couple hanging frame kt Mitchwini bear snoopy children photo wall"};PublicStatic string[] Price=Newstring[]{"450","1450","150","45","3999","99","129","4999","899","270","298","6999","1299","29","19"};PublicStaticInt[] Image=NewInt[]{R.drawable.mp4, R.drawable.bag, R.DRAWABLE.BQZ, R.DRAWABLE.BT, R.DRAWABLE.IBM, r.drawable.nokia3310, R.DRAWABLE.DD, R.DRAWABLE.DV, R.drawable.eh, R.drawable.hqz, R.drawable.hqz, R.drawable.hs, R.drawable.watch, R.DRAWABLE.WJ, r.drawable.xk};PrivateIntPositionPrivate list<goods>ListPrivateGoods G;PrivateBaseadapter adapter;PrivateListView ListView; @OverrideProtectedvoidOnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); ListView =(ListView) Findviewbyid (R.id.listview); adapter =New Activitylist (mainactivity.This, Getcon ()); Listview.setadapter (adapter);Registerforcontextmenu (listview);} @OverridePublicvoidOncreatecontextmenu (ContextMenu menu, View V, contextmenuinfo menuinfo) {//TODO auto-generated Method StubSuper.oncreatecontextmenu (menu, V, menuinfo); Menu.add (0,1, Menu.none,"Add entry"); Menu.add (0,2, Menu.none,"Delete entry"); Menu.add (0,3,menu.none,"Modify Entry"); Menu.add (0,4, Menu.none,"Query entry"); Menu.setheadericon (R.drawable.ic_launcher); Menu.setheadertitle ("Context Menu"); } @OverridePublicBoolean oncontextitemselected (MenuItem item) {//TODO auto-generated Method StubAdaptercontextmenuinfo menuinfo=(Adaptercontextmenuinfo) Item.getmenuinfo (); Position =Menuinfo.position;Switch(Item.getitemid ()) {Case1: G.setimage (R.drawable.ic_launcher); G.setname ("Android "); G.setprice ( "200"); List.add (g); Adapter.notifydatasetchanged (); Break Case 2:list.remove (position); Adapter.notifydatasetchanged (); Break Case 3:break; Case 4:listview.setonitemclicklistener (New Onitemclicklistener () {@Override public void Onitemclick (ADAPTERVIEW<? > arg0, view view, int arg2, long arg3) {//TODO auto-generated method stub Intent Intent = new Intent (mainactivity.th is, Showactivity.class); Intent.putextra ("image", image[arg2]); Intent.putextra ("name", Name[arg2]); Intent.putextra ("Price", price[arg2]); StartActivity (Intent); } }); Break } return super.oncontextitemselected (item); } private list<goods> Getcon () {List = new arraylist<goods> (); for (int i=0;i<image.length;i++) {g = new G Oods (); G.setimage (Image[i]); G.setname (Name[i]); G.setprice (Price[i]); List.add (g); } return list; }}

Android context Menu

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.