Created
January 25, 2017 10:23
-
-
Save pvankouteren/f4e961dccc9bc9fda8d3cc7247f06ee3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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