Listview获取项目文本
我需要获取所选项目的文本(不是 ID)。 我可以在 onListItemClick 下写什么来做到这一点? 我得到:
java.lang.ClassCastException: org.eclipse.jdt.internal.debug.core.model.JDIObjectValue cannot be cast to org.eclipse.jdt.debug.core.IJavaArray
at org.eclipse.jdt.internal.debug.ui.JavaDetailFormattersManager.getCompiledExpression(JavaDetailFormattersManager.java:396)
at org.eclipse.jdt.internal.debug.ui.JavaDetailFormattersManager.resolveFormatter(JavaDetailFormattersManager.java:167)
at org.eclipse.jdt.internal.debug.ui.JavaDetailFormattersManager.access$1(JavaDetailFormattersManager.java:152)
at org.eclipse.jdt.internal.debug.ui.JavaDetailFormattersManager$3.run(JavaDetailFormattersManager.java:143)
at org.eclipse.jdt.internal.debug.core.model.JDIThread$ThreadJob.run(JDIThread.java:2751)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
I need to grab selected item TEXT (not id).
What can I write under onListItemClick to do that?
I get:
java.lang.ClassCastException: org.eclipse.jdt.internal.debug.core.model.JDIObjectValue cannot be cast to org.eclipse.jdt.debug.core.IJavaArray
at org.eclipse.jdt.internal.debug.ui.JavaDetailFormattersManager.getCompiledExpression(JavaDetailFormattersManager.java:396)
at org.eclipse.jdt.internal.debug.ui.JavaDetailFormattersManager.resolveFormatter(JavaDetailFormattersManager.java:167)
at org.eclipse.jdt.internal.debug.ui.JavaDetailFormattersManager.access$1(JavaDetailFormattersManager.java:152)
at org.eclipse.jdt.internal.debug.ui.JavaDetailFormattersManager$3.run(JavaDetailFormattersManager.java:143)
at org.eclipse.jdt.internal.debug.core.model.JDIThread$ThreadJob.run(JDIThread.java:2751)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
传递给
onItemClick
的内容之一是被单击的视图:将
view
转换为适当的类型并对其调用getText()
;例如:One of the things passed to
onItemClick
is the view that was clicked:Cast
view
to the appropriate type and callgetText()
on it; for example:有多种方法可以实现此目的,这还取决于您是从简单的 listView 还是从自定义 ListView(使用 custom_list_item.xml)获取文本。
对于简单ListView
lv.setOnItemClickListener(new OnItemClickListener() {
对于自定义ListView
There are multiple ways to achieve this and it also depends on whether you are getting text from simple listView or from Custom ListView(with custom_list_item.xml).
For Simple ListView
lv.setOnItemClickListener(new OnItemClickListener() {
For Custom ListView