Android中我在同一个页面中使用2个ListView显示固定数据,但是当要显示第二个ListView的数据时出现问题.
代码:publicclassSettingActivityextendsActivity{//推送消息设置的ListViewListViewsetmessListView...
代码:
public class SettingActivity extends Activity {
// 推送消息设置的ListView ListView setmessListView;
// 在线状态设置的ListView
ListView setonlineListView;
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
// 显示自定义标题栏
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.setting);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
R.layout.title_bar);
// 找到推销消息设置的ListView setmessListView = (ListView) this.findViewById(R.id.setMessageListView);
ShowsetMessageItem();
// 找到在线状态设置的ListView
setonlineListView = (ListView) this.findViewById(R.id.setOnlineListView);
ShowsetOnlineItem();
View v;
}
/** 显示“推送消息”设置的条目*/
private void ShowsetMessageItem() {
// 存放条目信息的List
List<HashMap<String, Object>> messageitems = new ArrayList<HashMap<String, Object>>();
MessageItmes m1 = new MessageItmes("QQ消息", ""); MessageItmes m2 = new MessageItmes("电脑在线时推送消息", "");
List<MessageItmes> list = new ArrayList<MessageItmes>();
list.add(m1);
list.add(m2);
for (MessageItmes m : list) {
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("name", m.getName());
map.put("togglebutton", null); // 开关按钮的状态
messageitems.add(map);
}
// 通过适配器将数据绑定
SimpleAdapter adapter = new SimpleAdapter(this, messageitems,
R.layout.setmessage_items, new String[] { "name",
"togglebutton" }, new int[] { R.id.messageOneColumn,
R.id.messageTwoColumn });
setmessListView.setAdapter(adapter);
}
/**显示在线状态设置所有条目*/
private void ShowsetOnlineItem() {
// 存放条目信息的List
List<HashMap<String, Object>> messageitems = new ArrayList<HashMap<String, Object>>();
MessageItmes m1 = new MessageItmes("iPone QQ在线", ""); MessageItmes m2 = new MessageItmes("手机QQ在线", "");
List<MessageItmes> list = new ArrayList<MessageItmes>();
list.add(m1);
list.add(m2);
for (MessageItmes m : list) {
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("name", m.getName());
map.put("checkBox", m.getText());
messageitems.add(map);
}
// 通过适配器将数据绑定
SimpleAdapter adapter = new SimpleAdapter(this, messageitems,
R.layout.setmessage_items, new String[] { "name", "checkBox" },
new int[] { R.id.setOnlineOne, R.id.setOnlineTwo });
setmessListView.setAdapter(adapter);
}
} 当只有一个ListView时显示正常图:
加入第二个ListView就出错了,显示异常了.如图:
求解. 展开
public class SettingActivity extends Activity {
// 推送消息设置的ListView ListView setmessListView;
// 在线状态设置的ListView
ListView setonlineListView;
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
// 显示自定义标题栏
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.setting);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
R.layout.title_bar);
// 找到推销消息设置的ListView setmessListView = (ListView) this.findViewById(R.id.setMessageListView);
ShowsetMessageItem();
// 找到在线状态设置的ListView
setonlineListView = (ListView) this.findViewById(R.id.setOnlineListView);
ShowsetOnlineItem();
View v;
}
/** 显示“推送消息”设置的条目*/
private void ShowsetMessageItem() {
// 存放条目信息的List
List<HashMap<String, Object>> messageitems = new ArrayList<HashMap<String, Object>>();
MessageItmes m1 = new MessageItmes("QQ消息", ""); MessageItmes m2 = new MessageItmes("电脑在线时推送消息", "");
List<MessageItmes> list = new ArrayList<MessageItmes>();
list.add(m1);
list.add(m2);
for (MessageItmes m : list) {
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("name", m.getName());
map.put("togglebutton", null); // 开关按钮的状态
messageitems.add(map);
}
// 通过适配器将数据绑定
SimpleAdapter adapter = new SimpleAdapter(this, messageitems,
R.layout.setmessage_items, new String[] { "name",
"togglebutton" }, new int[] { R.id.messageOneColumn,
R.id.messageTwoColumn });
setmessListView.setAdapter(adapter);
}
/**显示在线状态设置所有条目*/
private void ShowsetOnlineItem() {
// 存放条目信息的List
List<HashMap<String, Object>> messageitems = new ArrayList<HashMap<String, Object>>();
MessageItmes m1 = new MessageItmes("iPone QQ在线", ""); MessageItmes m2 = new MessageItmes("手机QQ在线", "");
List<MessageItmes> list = new ArrayList<MessageItmes>();
list.add(m1);
list.add(m2);
for (MessageItmes m : list) {
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("name", m.getName());
map.put("checkBox", m.getText());
messageitems.add(map);
}
// 通过适配器将数据绑定
SimpleAdapter adapter = new SimpleAdapter(this, messageitems,
R.layout.setmessage_items, new String[] { "name", "checkBox" },
new int[] { R.id.setOnlineOne, R.id.setOnlineTwo });
setmessListView.setAdapter(adapter);
}
} 当只有一个ListView时显示正常图:
加入第二个ListView就出错了,显示异常了.如图:
求解. 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询