0
我試圖用自定義適配器過濾listview。當我開始在edittext上輸入時,應該過濾列表視圖。以下是適配器的代碼。自定義對象具有重寫方法toString,它返回Facebook用戶的名稱。我沒有重寫ArrayAdapter方法getItem,添加或刪除。ListView ArrayAdapter過濾 - 重複項目
public class FacebookFriendsAdapter extends ArrayAdapter<FacebookUser> {
private Activity activity;
public ImageLoader imageLoader;
private HashMap<String, Integer> alphaIndexer;
private String[] sections = new String[0];
private boolean enableSections;
public FacebookFriendsAdapter(Context context, int textViewResourceId,ArrayList<FacebookUser> newItems) {
super(context, textViewResourceId, newItems);
imageLoader = new ImageLoader(context.getApplicationContext());
}
public static class ViewHolder {
public TextView text;
public ImageView image;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View rowView = convertView;
FacebookUser fcbu = getItem(position);
if (convertView == null) {
LayoutInflater vi = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
rowView = vi.inflate(R.layout.facebook_friendslist_row, null);
final ViewHolder holder = new ViewHolder();
holder.text = (TextView) rowView.findViewById(R.id.facebook_rowFriendName);
holder.image = (ImageView) rowView.findViewById(R.id.facebookRowUserFoto);
rowView.setTag(holder);
} else {
rowView = convertView;
}
ViewHolder holder = (ViewHolder) rowView.getTag();
String imageurl = "http://graph.facebook.com/" + fcbu.getId()+ "/picture";
holder.text.setText(fcbu.getName());
holder.image.setTag(imageurl);
imageLoader.DisplayImage(imageurl, holder.image);
return rowView;
}
}
上的活動持有的EditText我創建了一個TextWatcher,如:
private TextWatcher filterTextWatcher = new TextWatcher() {
public void afterTextChanged(Editable s) {
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
public void onTextChanged(CharSequence s, int start, int before,
int count) {
facebookAdapter.getFilter().filter(s);
}
};
一切正常預期過濾列表後,經過濾項被複制。
如果有什麼可能導致這種情況,我將不勝感激。 謝謝
通過重複,你的意思是每個2,每個隨機數,他們似乎重複,當你滾動......? –
是的,每個都有2個。 – user738686