package com.example.listview;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
public class MainActivity extends Activity {
private ListView listView;
private ArrayAdapter<String> arrayAdapter;
private SimpleAdapter simpleAdapter;
private List<Map<String, Object>> dataList;
private TextView text;
private ImageView pic;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setContentView(R.layout.item);
setContentView(R.layout.main);
listView = (ListView) findViewById(R.id.listView);
text =(TextView) findViewById(R.id.text);
pic =(ImageView) findViewById(R.id.pic);
dataList = new ArrayList<Map<String, Object>>();
getData();
String[] arr_dataStrings = { "ash1", "ash2", "ash3", "ash4" };
arrayAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, arr_dataStrings);
simpleAdapter = new SimpleAdapter(this, dataList, R.layout.item,
new String[] { "pic", "text" },
new int[] { R.id.pic, R.id.text });
//listView.setAdapter(arrayAdapter);
listView.setAdapter(simpleAdapter);
}
private List<Map<String, Object>> getData() {
for (int i = 0; i < 20; i++) {
//dataList = new ArrayList<Map<String, Object>>();
Map<String, Object> map = new HashMap<String, Object>();
map.put("pic", R.drawable.ic_launcher);
map.put("txt", "ash" + i);
dataList.add(map);
}
return dataList;
}
}