Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save pvankouteren/f4e961dccc9bc9fda8d3cc7247f06ee3 to your computer and use it in GitHub Desktop.
Save pvankouteren/f4e961dccc9bc9fda8d3cc7247f06ee3 to your computer and use it in GitHub Desktop.
package com.example.sampleapp;
import java.util.ArrayList;
import java.util.HashMap;
import android.app.ListActivity;
import android.os.Bundle;
import android.widget.SimpleAdapter;
public class MoreScreen extends ListActivity {
ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>(
2);
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.screen_more);
HashMap<String, String> map;
map = new HashMap<String, String>();
map.put("line1", "Foo");
map.put("line2", "Bar");
list.add(map);
map = new HashMap<String, String>();
map.put("line1", "Hi");
map.put("line2", "Bye");
list.add(map);
// the from array specifies which keys from the map
// we want to view in our ListView
String[] from = { "line1", "line2" };
// the to array specifies the TextViews from the xml layout
// on which we want to display the values defined in the from array
int[] to = { android.R.id.text1, android.R.id.text2 };
// create the adapter and assign it to the listview
SimpleAdapter adapter = new SimpleAdapter(this, list,
android.R.layout.simple_list_item_2, from, to);
setListAdapter(adapter);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment