【发布时间】:2014-07-10 21:51:26
【问题描述】:
我是 Java 新手。
错误:(40, 5) 错误:方法未覆盖或实现超类型中的方法
错误:(32, 27) 错误:不兼容的类型:对象无法转换为长型
在
@Override
public long getItemId(int position) {
String item = getItem(position);
return hashMap.get(item);
}
完整代码如下
package com.javapapers.android.listview;
import android.content.Context;
import android.widget.ArrayAdapter;
import java.util.HashMap;
import java.util.List;
public class SimpleArrayAdapter extends ArrayAdapter {
Context context;
int textViewResourceId;
private static final String TAG = "SimpleArrayAdapter" ;
HashMap hashMap = new HashMap();
public SimpleArrayAdapter(Context context, int textViewResourceId,
List objects) {
super(context, textViewResourceId, objects);
this.context = context;
this.textViewResourceId = textViewResourceId;
for (int i = 0; i < objects.size(); ++i) {
hashMap.put(objects.get(i), i);
}
}
@Override
public long getItemId(int position) {
String item = getItem(position);
return hashMap.get(item);
}
@Override
public boolean hasStableIds() {
return true;
}
@Override
public void add(String object){
hashMap.put(object,hashMap.size());
this.notifyDataSetChanged();
}
}
【问题讨论】: