安卓中GridView填充簡單的文字和圖片,筆記!
阿新 • • 發佈:2019-02-04
mGrid = (GridView) findViewById(R.id.mainGrid); data_list = new ArrayList<Map<String, Object>>(); data_list=getData(); //建立介面卡 String [] from ={"image","text"}; int [] to = {R.id.image,R.id.title};//grid_item佈局中的兩個控制元件id simple_adapter = new SimpleAdapter(this, data_list, R.layout.grid_item, from, to); mGrid .setAdapter(simple_adapter); public List<Map<String, Object>> getData(){ for(int i=0;i<8;i++){ Map<String, Object> map = new HashMap<String, Object>(); map.put("image", new int[]{R.drawable.revoke, R.drawable.returngoods, R.drawable.transaction_record, R.drawable.pre_authorization, R.drawable.offline, R.drawable.print, R.drawable.manage, R.drawable.balances }[i]); map.put("text", new String[]{getString(R.string.menu_revoke), getString(R.string.menu_return), getString(R.string.menu_transaction_record), getString(R.string.menu_preAuth) ,getString(R.string.menu_offline), getString(R.string.menu_print), getString(R.string.menu_manage), getString(R.string.menu_query_balance)}[i]); data_list.add(map); } return data_list; }