csh_34 2013-04-22 03:34 采纳率: 0%
浏览 2466

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.this, "ID '" + 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)
  • 写回答

1条回答 默认 最新

  • LiDaming_and 2013-04-22 09:59
    关注

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

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

    使用:

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

    能改正你的问题。

    评论

报告相同问题?

悬赏问题

  • ¥15 虚拟机打包apk出现错误
  • ¥30 最小化遗憾贪心算法上界
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝