我有问题来过滤我的listview,但找不到适合我情况的好例子。实际上我的listview是我的Facebook朋友列表和图像。我的课是一个实现文本观察者的活动,下面是我的代码。
public ArrayAdapter<String> adapter = null;
friendFilter = (EditText) findViewById(R.id.friends_filter);
friendList = (ListView) findViewById(R.id.fb_friend_list);
friendList.setOnItemClickListener(this);
friendFilter.addTextChangedListener(this);
adapter = new FbFriendListAdapter(getApplicationContext(),nameIDPath, friendName);
friendList.setAdapter(adapter);
friendList.setTextFilterEnabled(true);
textwatcher ontextchanged,
public void onTextChanged(CharSequence s, int start, int before, int count) {
Log.d("adapter count", "adapter count " + adapter.getCount());
adapter.getFilter().filter(s);
}
我的适配器
public class FbFriendListAdapter extends ArrayAdapter<String>{
public static FriendsGetProfilePics model;
private ArrayList<String> nameIDPath;
private Context context;
Bitmap icon;
Hashtable<Integer, Bitmap> friendsImages;
public FbFriendListAdapter(Context c, ArrayList<String> nameIDPath, List<String> friendName){
super(c, R.layout.fb_friend_adapter, friendName);
this.nameIDPath = nameIDPath;
this.context = c;
if(model==null){
model = new FriendsGetProfilePics();
}
model.setListener(this);
}
public int getCount() {
return nameIDPath.size();
}
public long getItemId(int position) {
return position;
}
static class ViewHolder{
public TextView descHolder;
public ImageView typeHolder;
}
public View getView(int position, View convertview, ViewGroup parent) {
ViewHolder vh;
vh = new ViewHolder();
if(convertview==null){
LayoutInflater inf = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertview = inf.inflate(R.layout.fb_friend_adapter, null,true);
vh.descHolder = (TextView) convertview.findViewById(R.id.fbFriendName);
vh.typeHolder = (ImageView) convertview.findViewById(R.id.fbImage);
convertview.setTag(vh);
}else{
vh = (ViewHolder)convertview.getTag();
}
String[] names = nameIDPath.get(position).toString().split("@NAMES");
String[] idpath = names[1].toString().split("@PATH");
vh.descHolder.setText(names[0]);
vh.typeHolder.setImageBitmap(model.getImage(idpath[0],idpath[1]));
return convertview;
}
}
请指导我。