android ListView is not a view
来源:互联网 发布:笑傲江湖武功 知乎 编辑:程序博客网 时间:2024/04/29 16:44
今天在学习android的ListView时,在XML布局文件里布局列表时,用的是ListView,代码中用SimpleAdapter绑定数据,然后运行时出现错误,错误提示为:ListView is not a view。在网上搜索这个错误信息,但是没有搜索到,然后我又搜索了simpleadapter的用法,此时我才发现原来是我的XML出错了,应该用TextView而不是ListView。。
<TextView
android:id="@+id/view1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/view2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
(以前的错误代码
<ListView
android:id="@+id/view1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<ListView
android:id="@+id/view2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
)
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
PrepareDate();
SimpleAdapter adapter=new SimpleAdapter(this,data,R.layout.list_view,new String[]{"姓名","性别"},new int[]{R.id.view1,R.id.view2});
listview=new ListView(this);
listview.setAdapter(adapter);
setContentView(listview);
}
private void PrepareDate(){
data=new ArrayList<Map<String,Object>>();
Map<String,Object> item;
item=new HashMap<String,Object>();
item.put("姓名", "张三");
item.put("性别","男");
data.add(item);
item=new HashMap<String,Object>();
item.put("姓名", "张三");
item.put("性别","男");
data.add(item);
item=new HashMap<String,Object>();
item.put("姓名", "张三");
item.put("性别","男");
data.add(item);
}
- android ListView is not a view
- java.lang.illegalargumentexception view android.widget.listview is not a sliding drawer
- error:Parent view is not a TextView
- BIRT a data view is not available
- Parent view is not a TextViewd的解决办法
- [Android界面] addView(View, LayoutParams) is not supported in AdapterView
- Android开发:UnsupportedOperationException: addView(View, LayoutParams) is not supported in ...
- android studio This view is not constrained问题
- Android Studio报错view is not constrained
- Added View has RecyclerView as parent but view is not a real child. Unfiltered index:0
- backbone中一个view调用另一个view的方法时报is not a constructor的问题
- ListView adapter getView 报错: addView(View, LayoutParams) is not supported in AdapterView
- Attempting to load the view of a view controller while it is deallocating is not allowed and may res
- Attempting to load the view of a view controller while it is deallocating is not allowed and may res
- $ is not a function
- $ is not a function
- is not a function
- android开发The method setOnClickListener(View.OnClickListener) in the type View is not错误
- Linux Crontab 定时任务 命令详解
- Nginx主主负载均衡架构
- struts result type redirect 重定向和转发的区别
- socket 心跳包机制
- 程序员面试什么最重要?
- android ListView is not a view
- [Python]网络爬虫(二):利用urllib2通过指定的URL抓取网页内容
- DOS7.1安装与学习
- 对锐雯的浅谈
- 集体智慧及其算法
- 大小端模式转换函数
- How To Create A Socket Based iPhone App and Server
- 高性能服务器(epoll精髓)
- 修改返回按钮 标题 (UINavigationBar)