|
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;
Public class Mainactivity extends Activity {
public static string[] name=new string[]{
"Patriot (Aigo) MP5 digital player U303 8GB touch screen MP3 white ",
" snow Man 2014 New Women's ol occupational shoulder bag female handbag crossbody bag 8305 m white ",
" long-sleeved dress chiffon skirt slim-fit female Europe and the United States long-run-chi-sen women dragged the big fairy dress ",
" Korea stationery cute creative fashion office supplies Big Multi-function storage box pen bag ",
" ThinkPad E531 6885-d4c Celeron duo 500G Lenovo IBM Business Notebook ",
" cash pack mail Shun Fung nokia/Nokia 107 dual SIM standby mobile phone extra long standby ",
" 3 Stripe North Plush Camisole Women's new built-in black strappy modal lace vest ",
" [Label 8G card]sony/Sony hdr-cx240e digital camera/DV HD professional Camera ",
" Natural white blue green chalcedony crystal earrings men and women 925 Tremella nail black agate Earrings anti-allergic silver jewelry ",
" 2014 Korean version of the European root yarn dress new Summer female embroidered princess puff skirt pink fake two pieces set of ",
" Hangyi 2014 summer new Korean version slim Lady dress women's lace chiffon fashion dress hipster ",
" hp/hp Envy Envy 15-j105tx four generation i7 high split screen 8G memory/1t/4g exclusive ",
" casio casio fashion quartz watch mens belt watch mtp-1095q-7b ",
" Genuine Hellokitty dolls kt plush toys Hello Kitty doll doll Tanabata birthday gift Girl ",
" genuine cartoon baby photo frame two couples hanging frame kt Mitchwini bear snoopy children photo Wall "
};
public static string[] Price=new string[]{
"450", "1450", "150", "45",
"3999", "99", "129", "4999", "899", "270", "298", "6999", "1299",
"29", "19"
};
public static int[] Image=new int[]{
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
};
private int position;
Private list<goods> List;
Private Goods G;
Private Baseadapter adapter;
Private ListView ListView;
@Override
protected void OnCreate (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);
}
@Override
public void Oncreatecontextmenu (ContextMenu menu, View V,
Contextmenuinfo menuinfo) {
TODO auto-generated Method Stub
Super.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");
}
@Override
public boolean oncontextitemselected (MenuItem item) {
TODO auto-generated Method Stub
Adaptercontextmenuinfo menuinfo= (Adaptercontextmenuinfo) item.getmenuinfo ();
Position = menuinfo.position;
Switch (Item.getitemid ()) {
Case 1:
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.this, 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 Goods ();
G.setimage (Image[i]);
G.setname (Name[i]);
G.setprice (Price[i]);
List.add (g);
}
return list;
}
}
|
|