Android 获取listview中的文本 报错:android.widget.LinearLayout cannot be cast to android.widget.TextView
来源:互联网 发布:java人机猜拳代码 编辑:程序博客网 时间:2024/06/06 03:07
之前是这么写的 运行到获取info就报错了
//点击设备列表private AdapterView.OnItemClickListener deviceClickListener = new AdapterView.OnItemClickListener() { //点击列表项,连接设备 public void onItemClick(AdapterView<?> av, View v, int arg2, long arg3) { String info = ((TextView) v).getText().toString(); }};
错误原因是你的ListView
行布局不仅包含TextView就会报错 解决办法是
private AdapterView.OnItemClickListener dataClickListener = new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> av, View v, int arg2, long arg3) { LinearLayout parent = (LinearLayout) v; TextView t = (TextView) parent.findViewById(R.id.text); Toast.makeText(getBaseContext(), t.getText(), Toast.LENGTH_LONG).show(); String info = (String) t.getText(); Log.i("测试","获取的结果等于 info="+info); } };
这样就可以获取到
info呢
阅读全文
0 0
- Android 获取listview中的文本 报错:android.widget.LinearLayout cannot be cast to android.widget.TextView
- android用Adapter实现ListView的初始化报错android.widget.LinearLayout cannot be cast to android.widget.TextView
- .ClassCastException: .LinearLayout cannot be cast to android.widget.TextView
- java.lang.ClassCastException: android.widget.LinearLayout cannot be cast to android.widget.TextView
- java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.LinearLayout
- 解决android.widget.LinearLayout cannot be cast to android.widget.ListView问题
- widget.Button cannot be cast to android.widget.ListView
- LinearLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
- android.widget.LinearLayout$LayoutParams cannot be cast to android.widget.RelativeLayout$LayoutPara
- android.widget.FrameLayout$LayoutParams cannot be cast to android.widget.LinearLayout$LayoutParams
- android.widget.RelativeLayout$LayoutParams cannot be cast to android.widget.LinearLayout$LayoutParam
- android.widget.LinearLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
- ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.widget.AbsLis
- android.widget.RelativeLayout$LayoutParams cannot be cast to android.widget.LinearLayout$LayoutParam
- android.widget.RelativeLayout$LayoutParams cannot be cast to android.widget.LinearLayout$LayoutParam
- 【Android】程序崩溃错误为Android.widget,textView cannot be cast to android.widget.button
- 【Android】程序崩溃错误为Android.widget,textView cannot be cast to android.widget.button
- cannot be cast to android.widget.HeaderViewListAdapter
- jQuery选择器与过滤器
- Python 清除线上数据oom内存溢出事件
- 1059. C语言竞赛(20)
- Sort the Array
- java对链表(环、交叉链表的应用)
- Android 获取listview中的文本 报错:android.widget.LinearLayout cannot be cast to android.widget.TextView
- linq insert The null value cannot be assigned to a member with type System.Int64 which is a non-null
- 出现GC overhead limit exceeded 的解决方案
- 1060. 爱丁顿数(25)
- 【数据库】实验一
- MySQL 存储过程中的游标使用
- 【软考】纠错1-3
- 结构体
- C语言小游戏相关问题,猜测两次后查询成绩排行榜,然后继续猜测并查询成绩排行榜,则排行榜显示为空