OnItemClickListener itemClickListener = new OnItemClickListener() {@OverrIDepublic voID onItemClick(AdapterVIEw<?> a,VIEw v,int position,long ID) { ListVIEw lv = (ListVIEw) a; if (lv.isItemChecked(position)) { Toast.makeText(getBaseContext(),"You checked " + values.get(position),Toast.LENGTH_SHORT).show(); TextVIEw row = (TextVIEw) findVIEwByID(androID.R.ID.text1); row.setPaintFlags(row.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG); } else { Toast.makeText(getBaseContext(),"You unchecked " + values.get(position),Toast.LENGTH_SHORT).show(); TextVIEw row = (TextVIEw) findVIEwByID(androID.R.ID.text1); row.setPaintFlags(row.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG); }}};
如果使用TextVIEw row =(TextVIEw)lv.getItemAtposition(position),则应用程序会崩溃 – logcat:
1-08 16:39:30.373:E / AndroIDRuntime(1934):未捕获的处理程序:由于未捕获的异常导致线程主要退出
01-08 16:39:30.383:E / AndroIDRuntime(1934):java.lang.classCastException:java.lang.String
01-08 16:39:30.383:E / AndroIDRuntime(1934):at com.jms.purchaseexamples.MainActivity $1.onItemClick(MainActivity.java:72)
01-08 16:39:30.383:E / AndroIDRuntime(1934):在androID.Widget.AdapterVIEw.performItemClick(AdapterVIEw.java:284)
01-08 16:39:30.383:E / AndroIDRuntime(1934):在androID.Widget.ListVIEw.performItemClick(ListVIEw.java:3285)
01-08 16:39:30.383:E / AndroIDRuntime(1934):在androID.Widget.AbsListVIEw $PerformClick.run(AbsListVIEw.java:1640)
01-08 16:39:30.383:E / AndroIDRuntime(1934):在androID.os.Handler.handleCallback(Handler.java:587)
01-08 16:39:30.383:E / AndroIDRuntime(1934):在androID.os.Handler.dispatchMessage(Handler.java:92)
01-08 16:39:30.383:E / AndroIDRuntime(1934):在androID.os.Looper.loop(Looper.java:123)
01-08 16:39:30.383:E / AndroIDRuntime(1934):在androID.app.ActivityThread.main(ActivityThread.java:4363)
01-08 16:39:30.383:E / AndroIDRuntime(1934):at java.lang.reflect.Method.invokeNative(Native Method)
01-08 16:39:30.383:E / AndroIDRuntime(1934):at java.lang.reflect.Method.invoke(Method.java:521)
01-08 16:39:30.383:E / AndroIDRuntime(1934):at com.androID.internal.os.ZygoteInit $MethodAndArgsCaller.run(ZygoteInit.java:860)
01-08 16:39:30.383:E / AndroIDRuntime(1934):at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:618)
01-08 16:39:30.383:E / AndroIDRuntime(1934):at dalvik.system.NativeStart.main(Native Method)
怎么样:
//Actually select the correct item from the ListvIEwTextVIEw row = (TextVIEw)lv.getItemAtposition(position);row.setPaintFlags(row.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG);总结
以上是内存溢出为你收集整理的android – 如何检查列表视图中的文本项?全部内容,希望文章能够帮你解决android – 如何检查列表视图中的文本项?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)