android.. R.layout.simple_item, new String[] { "", "", "" }, ///此处的from字符串数组这样写正确吗?
importjava.util.ArrayList;importandroid.app.Activity;publicclassSimpleAdapterTestexte...
import java.util.ArrayList;
import android.app.Activity;
public class SimpleAdapterTest extends Activity {
private String[] names = new String[] { "张三", "李四", "王五", "赵六" };
private String[] descs = new String[] { "一个农民", "一个长工", "一个混混", "一个捕快" };
private int[] imageIds = new int[] { R.drawable.ic_launcher,
R.drawable.ic_launcher, R.drawable.ic_launcher,
R.drawable.ic_launcher };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// 创建一个List集合,List集合的元素是Map
List<Map<String, Object>> listItems = new ArrayList<Map<String, Object>>();
for (int i = 0; i < names.length; i++) {
Map<String, Object> listItem = new HashMap<String, Object>();
listItem.put("header", imageIds[i]); //////HashMap,put了三次,这样也正确?不理解啊?
listItem.put("personName", names[i]);
listItem.put("desc", descs[i]);
listItems.add(listItem);
// 创建一个SimpleAdapter
SimpleAdapter simpleAdapter = new SimpleAdapter(this, listItems,
R.layout.simple_item, new String[] { "", "", "" }, ////////此处的from字符串数组这样写正确吗?
new int[] { R.id.name, R.id.header, R.id.desc });
ListView listView = (ListView) findViewById(R.id.mylistView);
// 为ListView设置Adapter
listView.setAdapter(simpleAdapter);
}
}
} 展开
import android.app.Activity;
public class SimpleAdapterTest extends Activity {
private String[] names = new String[] { "张三", "李四", "王五", "赵六" };
private String[] descs = new String[] { "一个农民", "一个长工", "一个混混", "一个捕快" };
private int[] imageIds = new int[] { R.drawable.ic_launcher,
R.drawable.ic_launcher, R.drawable.ic_launcher,
R.drawable.ic_launcher };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// 创建一个List集合,List集合的元素是Map
List<Map<String, Object>> listItems = new ArrayList<Map<String, Object>>();
for (int i = 0; i < names.length; i++) {
Map<String, Object> listItem = new HashMap<String, Object>();
listItem.put("header", imageIds[i]); //////HashMap,put了三次,这样也正确?不理解啊?
listItem.put("personName", names[i]);
listItem.put("desc", descs[i]);
listItems.add(listItem);
// 创建一个SimpleAdapter
SimpleAdapter simpleAdapter = new SimpleAdapter(this, listItems,
R.layout.simple_item, new String[] { "", "", "" }, ////////此处的from字符串数组这样写正确吗?
new int[] { R.id.name, R.id.header, R.id.desc });
ListView listView = (ListView) findViewById(R.id.mylistView);
// 为ListView设置Adapter
listView.setAdapter(simpleAdapter);
}
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询