趁着有空,连着发两篇,是我前两天看视频学过的内容,不大体上发发,我怕我遗忘了。
言归正传,这次主要是布局,因为一开始总用的LinearLayout,略显粗糙,这次看的包括了相对布局RelativeLayout,以及LinearLayout的嵌套布局。控件部分了解了进度条和单选框复选框的代码的使用。代码比较简单,也没出现什么大错,安装完出现了一次异常闪退,系统也没提示错误,返回头来看错误主要是将RelativeLayout改变为LinearLayout时多敲了一个Layout。
出现大问题的就是ListView了,一直是异常闪退,直到现在我还没查明白到底哪出错了,下面附上代码以及系统提示的错误,如果有好心人看到了。希望可以帮我解疑答惑。
public class Main7Activity extends ListActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main7);
ArrayList<HashMap<String,String>> list=new ArrayList<>();
HashMap<String,String> map1=new HashMap<>();
HashMap<String,String> map2=new HashMap<>();
HashMap<String,String> map3=new HashMap<>();
map1.put("user_name","zhangsan");
map1.put("user_ip","192.168.0.1");
map2.put("user_name","lisi");
map2.put("user_ip","192.168.0.2");
map3.put("user_name","wangwu");
map3.put("user_ip","192.168.0.3");
list.add(map1);
list.add(map2);
list.add(map3);
SimpleAdapter listAdapter=new SimpleAdapter(this,list,R.layout.activity_main7_1,
new String[]{"user_name","user_ip"},
new int[]{R.id.user_ip,R.id.user_name});
setListAdapter(listAdapter);
}
}
java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list' 并没有找到应该在什么地方去改这个错误,跪求大神。