我是Java的新手.
Error:(40, 5) error: method does not override or implement a method from a supertype
Error:(32, 27) error: incompatible types: Object cannot be converted to long
在
@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();
}
}