SimpleAdapter中设定了 R.layout.listview_item
2017-01-02 07:44
381 查看
private static final String TAG = "MainActivity";
private List<Person> persons;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mButton = (Button) findViewById(R.id.button1);
mListView = (ListView) findViewById(R.id.listView1);
mButton.setOnClickListener(new MyOnClickListener());
}
private class MyOnClickListener implements OnClickListener {
@SuppressLint("ShowToast")
@Override
public void onClick(View v) {
try {
// 得到Json解析成功之后数据
persons = JsonParse.getListPerson(urlPath);
List<HashMap<String, Object>> data = new ArrayList<HashMap<String, Object>>();
for (int i = 0; i < persons.size(); i++) {
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("id",persons.get(i).getId());
map.put("name", persons.get(i).getName());
map.put("password", persons.get(i).getPassword());
map.put("age", persons.get(i).getAge());
map.put("sex",persons.get(i).getSex());
map.put("hobby",persons.get(i).getHobby());
map.put("city",persons.get(i).getCity());
data.add(map);
}
SimpleAdapter _Adapter = new SimpleAdapter(MainActivity.this,
data, R.layout.listview_item, new String[] { "id","name",
"password", "age","sex","hobby","city" }, new int[] { R.id.textView1,
R.id.textView2, R.id.textView3, R.id.textView4, R.id.textView5, R.id.textView6, R.id.textView7 });
mListView.setAdapter(_Adapter);
} catch (Exception e) {
Toast.makeText(MainActivity.this, "解析失败", 2000).show();
Log.i(TAG, e.toString());
}
}
这里的lisR.layout.listview_item,, R.id.textView1,R.id.button1,,R.id.listView1在xml中怎么写。。才可以显示在应用上
private List<Person> persons;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mButton = (Button) findViewById(R.id.button1);
mListView = (ListView) findViewById(R.id.listView1);
mButton.setOnClickListener(new MyOnClickListener());
}
private class MyOnClickListener implements OnClickListener {
@SuppressLint("ShowToast")
@Override
public void onClick(View v) {
try {
// 得到Json解析成功之后数据
persons = JsonParse.getListPerson(urlPath);
List<HashMap<String, Object>> data = new ArrayList<HashMap<String, Object>>();
for (int i = 0; i < persons.size(); i++) {
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("id",persons.get(i).getId());
map.put("name", persons.get(i).getName());
map.put("password", persons.get(i).getPassword());
map.put("age", persons.get(i).getAge());
map.put("sex",persons.get(i).getSex());
map.put("hobby",persons.get(i).getHobby());
map.put("city",persons.get(i).getCity());
data.add(map);
}
SimpleAdapter _Adapter = new SimpleAdapter(MainActivity.this,
data, R.layout.listview_item, new String[] { "id","name",
"password", "age","sex","hobby","city" }, new int[] { R.id.textView1,
R.id.textView2, R.id.textView3, R.id.textView4, R.id.textView5, R.id.textView6, R.id.textView7 });
mListView.setAdapter(_Adapter);
} catch (Exception e) {
Toast.makeText(MainActivity.this, "解析失败", 2000).show();
Log.i(TAG, e.toString());
}
}
这里的lisR.layout.listview_item,, R.id.textView1,R.id.button1,,R.id.listView1在xml中怎么写。。才可以显示在应用上
相关文章推荐
- Android:ListView、SimpleAdapter、设置不同行布局、getViewTypeCount、getItemViewType
- Android ListView 之 SimpleAdapter 二 (包含 item 中按钮监听)
- Android UI学习 - ListView (android.R.layout.simple_list_item_1是个什么东西)
- Android ListView 之 SimpleAdapter 二 (包含 item 中按钮监听)
- 分别使用simpleAdapter和baseAdapter为ListView的Item添加按钮响应事件
- android listView 更改simpleAdapter中布局layout中textView颜色
- Android UI学习 - ListView (android.R.layout.simple_list_item_1是个什么东西)
- Android ListView 之 SimpleAdapter 二 (包含 item 中按钮监听)
- 分别使用simpleAdapter和baseAdapter为ListView的Item添加按钮响应事件
- Android 使用SimpleCursorAdapter为listview的item添加按钮
- ListView加ArrayAdapter结合android.R.layout.activity_list_item快速实现图文显示
- simpleCursorAdapter中的listview获取内容
- ListView与SimpleCursorAdapter实现视频列表
- ListView适配器--ArrayAdapter;SimpleAdapter;SimpleCursorAdapter
- 设置listview的adapter时,item下面的下划线有高有低,部分左右有缩进,部分完全填充宽度
- Android UI 设计:ListView 控件与 SimpleAdapter 适配器
- 【Android】利用ArrayAdapter/SimpleAdapter创建ListView
- Android--ListView之SimpleAdapter的使用(转)
- 使用SimpleAdapter创建ListView,加入了点击事件,并传值
- android ListView,SimpleCursorAdapter