public class MainActivity extends Activity { private GridView gview; private GridView gview1; private List<Map<String, Object>> data_list; private List<Map<String, Object>> data_list1; private SimpleAdapter sim_adapter; private SimpleAdapter sim_adapter1; private int[] icon = {R.drawable.myfriend, R.drawable.mybooklist, R.drawable.mycollection}; private int[] icon1 = {R.drawable.homepage_unselected,R.drawable.dynamic_unselected, R.drawable.message_unselected,R.drawable.me_unselected}; private String[] iconname = {"好友列表", "我的订单", "我的收藏"}; private String[] iconname1 = {"首页","动态","消息","我"}; private ImageView imageView; public Activity activity=this; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.choosepic); imageView = (ImageView) findViewById(R.id.icon); imageView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { final String[] arr = {"拍照", "相册"}; // 弹出列表对话框 new AlertDialog.Builder(MainActivity.this).setTitle("请选择").setItems(arr, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (which == 0) { FaceUtil.openCamera(activity); } if (which == 1) { FaceUtil.choosePhoto(activity); } } }).setNegativeButton("取消", null).create().show(); } }); gview=(GridView) findViewById(R.id.gview); gview1= (GridView) findViewById(R.id.gview1); data_list=new ArrayList<>(); data_list1=new ArrayList<>(); getData(); getData1(); String[] from = {"icon", "iconname"}; String[] from1 = {"icon1","iconname1"}; int[] to = {R.id.imgview, R.id.iconname}; int[] to1 = {R.id.imgview1,R.id.iconname1}; sim_adapter=new SimpleAdapter(this,data_list, R.layout.view1, from, to); sim_adapter1=new SimpleAdapter(this,data_list1,R.layout.view2,from1,to1); gview.setAdapter(sim_adapter); gview1.setAdapter(sim_adapter1); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); switch (requestCode) { case FaceUtil.REQUEST_PICTURE_CHOOSE: FaceUtil.dealPic(activity,imageView,requestCode,resultCode,data); break; case FaceUtil.REQUEST_CAMERA_IMAGE: FaceUtil.dealPic(activity,imageView,requestCode,resultCode,data); break; case FaceUtil.REQUEST_CROP_IMAGE: FaceUtil.dealPic(activity,imageView,requestCode,resultCode,data); break; default: break; } } public List<Map<String, Object>> getData() { for (int i = 0; i < icon.length; i++) { Map<String, Object> map = new HashMap<String, Object>(); map.put("icon", icon[i]); map.put("iconname", iconname[i]); data_list.add(map); } return data_list; } public List<Map<String, Object>> getData1() { for (int i = 0; i < icon1.length; i++) { Map<String, Object> map = new HashMap<String, Object>(); map.put("icon1", icon1[i]); map.put("iconname1", iconname1[i]); data_list1.add(map); } return data_list1; } }
蜂之谷
相关分类