1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| public class Myafor5Activity extends AppCompatActivity {
ListView list=null;
private List<Map<String, Object>> data;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_myafor5);
PrepareData();
list = new ListView(this);
// list= (ListView) findViewById(R.id.listView);
SimpleAdapter adapter = new SimpleAdapter(this, data,android.R.layout.simple_list_item_1, new String[] { "AAA" },
new int[] { android.R.id.text1 });
list.setAdapter(adapter);
setContentView(list);
AdapterView.OnItemClickListener listener = new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
setTitle(parent.getItemAtPosition(position).toString());
}
};
list.setOnItemClickListener(listener);
}
private void PrepareData() {
data = new ArrayList<Map<String, Object>>();
Map<String, Object> item;
item = new HashMap<String, Object>();
item.put("1", "A");
item.put("2", "B");
data.add(item);
item = new HashMap<String, Object>();
item.put("3", "C");
item.put("4", "D");
data.add(item);
item = new HashMap<String, Object>();
item.put("5", "E");
item.put("6", "F");
data.add(item);
}
} |
Partager