我试图用自定义适配器过滤列表视图。当我开始在 edittext 上输入时,应该过滤列表视图。下面是适配器的代码。自定义对象已覆盖返回 facebook 用户名称的 toString 方法。我没有覆盖 ArrayAdapter 方法 getItem、添加或删除。
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);
}
};
一切正常,期望在过滤列表后过滤的项目被复制。
A会很感激任何可能导致这种情况的想法。谢谢