Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- // Each row in the list stores name, wt and icon.
- List<HashMap<String,String>> aList = new ArrayList<HashMap<String,String>>();
- for(int i=0;i<icon.length;i++){
- HashMap<String, String> hm = new HashMap<String,String>();
- hm.put("name", "Name : " + name[i]);
- hm.put("wt","Wt. : " + quantity[i]);
- hm.put("icon", Integer.toString(icon[i]) );
- aList.add(hm);
- }
- // Keys used in Hashmap
- String[] from = { "icon","name","wt" };
- // Ids of views in listview_layout
- int[] to = { R.id.icon,R.id.firstLine,R.id.secondLine};
- // Instantiating an adapter to store each items
- // R.layout.listview_layout defines the layout of each item
- SimpleAdapter adapter = new SimpleAdapter(getBaseContext(), aList, R.layout.listview_layout, from, to);
- // Getting a reference to listview of main.xml layout file
- ListView listView = ( ListView ) findViewById(R.id.listview);
- // Setting the adapter to the listView
- listView.setAdapter(adapter);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement