listview-Hashmap代码在 simpleadapter 数组运行但不能在 custom array adapter 中运行

问题描述

Hashmap代码在 simpleadapter 数组运行但不能在 custom array adapter 中运行
下面的 Hashmap代码在 simpleadapter 数组中可以运行但是在自定义的 adapter 数组中不能运行,为什么呢?

我使用的 lazyLoading 类来加载图像。

public void onItemClick(AdapterView<?> parent View view                    int position long id) {                HashMap<String String> o = (HashMap<String String>) list.getItemAtPosition(position);                Toast.makeText(CustomizedListView.thisID '"" + o.get(""KEY_TITLE"") + ""' was clicked."" Toast.LENGTH_SHORT).show();             }     

当点击显示的时候,程序就崩溃。
LogCAT:

threadid=1: thread exiting with uncaught exception (group=0x40ab0228) FATAL EXCEPTION: main java.lang.ClassCastException: java.lang.Integer cannot be cast to java.util.HashMap    at com.example.androidhive.CustomizedListView$1.onItemClick(CustomizedListView.java:94)    at android.widget.AdapterView.performItemClick(AdapterView.java:292)    at android.widget.AbsListView.performItemClick(AbsListView.java:1077)    at android.widget.AbsListView$PerformClick.run(AbsListView.java:2533)    at android.widget.AbsListView$1.run(AbsListView.java:3198)    at android.os.Handler.handleCallback(Handler.java:605)    at android.os.Handler.dispatchMessage(Handler.java:92)    at android.os.Looper.loop(Looper.java:154)    at android.app.ActivityThread.main(ActivityThread.java:4945)    at java.lang.reflect.Method.invokeNative(Native Method)    at java.lang.reflect.Method.invoke(Method.java:511)    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)    at dalvik.system.NativeStart.main(Native Method)

解决方案

在自定义的 Adapter 中你是返回位置,而不是item

public Object getItem(int position) {            return position;        }

使用:

public Object getItem(int position) {                return data.get(position);            }

能改正你的问题。

时间: 2024-09-08 14:50:25

listview-Hashmap代码在 simpleadapter 数组运行但不能在 custom array adapter 中运行的相关文章

iOS多线程的初步研究(四、五、六)--NSTimer--NSURLConnection子线程中运行 ---- NSOperation

iOS多线程的初步研究(四)-- NSTimer 理解run loop后,才能彻底理解NSTimer的实现原理,也就是说NSTimer实际上依赖run loop实现的. 先看看NSTimer的两个常用方法: + (NSTimer *)timerWithTimeInterval:(NSTimeInterval)ti target:(id)aTarget selector:(SEL)aSelector userInfo:(id)userInfo repeats:(BOOL)yesOrNo; //生成

python在shell中运行正常,但在windows中经常报错

问题描述 python在shell中运行正常,但在windows中经常报错 我写了一个获取网页信息的文件,在shell中测试,运行情况良好,但是直接双击打开py文件,则经常闪退.以下是代码.这种情况我不是很了解,求帮助. # -*- coding: utf-8 -*-import urllib2import urllibimport reimport threadimport timeimport json#----------加载处理Steam市场--------------class Spi

调试-汇编dosbox中运行程序,不是debug 1.exe的那种

问题描述 汇编dosbox中运行程序,不是debug 1.exe的那种 比如 直接输入 1.exe运行 而不是 debug 1.exedosbox中运行的程序进入死循环或者无响应状态 如何停止其运行一般是程序编写出了问题 如何停止它的运行 只能关了dosbox吗 解决方案 试试看ctrl+break 解决方案二: 似乎只能关了dosbox,毕竟dos是单任务的,一直在执行你的程序,就算你给了结束进程的指令系统也接不到. 解决方案三: vc下运行程序正常,运行debug下exe报错退出

查询在应用程序运行得很慢, 但在SSMS运行得很快的原因探究

原文:查询在应用程序运行得很慢, 但在SSMS运行得很快的原因探究 查询在应用程序运行得很慢, 但在SSMS运行得很快的原因探究 -理解性能疑点 1      引言 内容来自http://www.sommarskog.se/query-plan-mysteries.html(Slow in the Application, Fast in SSMS?) [看国内没有人好好翻译过这篇.全部翻译实在太长了,就挑主要的意译了.如果要看完整版,还是建议读原文.先翻译了一半,先解决了眼前的问题.剩下的一般

math.h-为何这段代码在DEV中运行结果错误

问题描述 为何这段代码在DEV中运行结果错误 #include<stdio.h> #include<math.h> int main() { int i; for(i=100;i<1000;i++) if(i==pow(i%10,3)+pow(i/100,3)+pow(i/10%10,3))printf("%dn",i); return 0; } 求所有3位数水仙花数 我提交到蓝桥杯练习平台结果却是正确的 解决方案 printf("%dn&quo

java代码中运行doc命令

问题描述 java代码中运行doc命令 我想要在我的Java代码中运行一段doc命令,然后将正常在doc窗口输出的信息取出来,这个信息应该怎么获取,求助各位大神 解决方案 java doc运行命令 解决方案二: http://developer.51cto.com/art/201107/273282.htm

怎么在代码里判断当前是调试运行(F5)还是不调试直接运行(Ctrl+F5)呢?

问题描述 怎么在代码里判断当前是调试运行(F5)还是不调试直接运行(Ctrl+F5)呢? 解决方案 解决方案二:一般用System.Diagnostics.Debug.Write来输出调试信息就行了,发布版本不会插入这些语句解决方案三:我需要判断到底是不是调试执行的,有没有这样的方法呢?谢谢了~~~引用1楼jinjazz的回复: 一般用System.Diagnostics.Debug.Write来输出调试信息就行了,发布版本不会插入这些语句 解决方案四:只能判断release和debug把

iostream-程序目的是通过排序算法进行数组由大到小排序 但不同编译器运行结果不一致

问题描述 程序目的是通过排序算法进行数组由大到小排序 但不同编译器运行结果不一致 程序目的是通过排序算法进行数组由大到小排序 但不同编译器运行结果不一致 #include <iostream> #include <iomanip> //使用setw()函数 using namespace std;//定义无参函数 void bubble(int[], int); int main() { int arry[10] = {11, 4, 55, 6, 77, 8, 9, 0, 7, 1

lua 环境隔离问题(同一份代码对象的多份拷贝,在同一个虚拟机中运行冲突问题)

问题描述 lua 环境隔离问题(同一份代码对象的多份拷贝,在同一个虚拟机中运行冲突问题) 1C 问大家一个问题,我有个lua工程,里面有很多的全局变量,现在需要在同一个lua虚拟机内,同时执行多个工程的代码,有没有什么好的解决方案,能将各个工程环境隔离