Advertisement
Guest User

Untitled

a guest
May 30th, 2015
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. /** Called when the activity is first created. */
  2. @Override
  3. public void onCreate(Bundle savedInstanceState) {
  4. super.onCreate(savedInstanceState);
  5. setContentView(R.layout.main);
  6.  
  7. // Each row in the list stores name, wt and icon.
  8. List<HashMap<String,String>> aList = new ArrayList<HashMap<String,String>>();
  9.  
  10. for(int i=0;i<icon.length;i++){
  11. HashMap<String, String> hm = new HashMap<String,String>();
  12. hm.put("name", "Name : " + name[i]);
  13. hm.put("wt","Wt. : " + quantity[i]);
  14. hm.put("icon", Integer.toString(icon[i]) );
  15. aList.add(hm);
  16. }
  17.  
  18. // Keys used in Hashmap
  19. String[] from = { "icon","name","wt" };
  20.  
  21. // Ids of views in listview_layout
  22. int[] to = { R.id.icon,R.id.firstLine,R.id.secondLine};
  23.  
  24. // Instantiating an adapter to store each items
  25. // R.layout.listview_layout defines the layout of each item
  26. SimpleAdapter adapter = new SimpleAdapter(getBaseContext(), aList, R.layout.listview_layout, from, to);
  27.  
  28. // Getting a reference to listview of main.xml layout file
  29. ListView listView = ( ListView ) findViewById(R.id.listview);
  30.  
  31. // Setting the adapter to the listView
  32. listView.setAdapter(adapter);
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement