Android 使用图像过滤ArrayAdapter ListView
我在筛选我的listview时遇到问题,找不到任何适合我的情况的好例子。实际上,我的listview是我的facebook好友列表和图片。我的类是一个实现文本监视程序的活动,下面是我的代码Android 使用图像过滤ArrayAdapter ListView,android,listview,android-arrayadapter,Android,Listview,Android Arrayadapter,我在筛选我的listview时遇到问题,找不到任何适合我的情况的好例子。实际上,我的listview是我的facebook好友列表和图片。我的类是一个实现文本监视程序的活动,下面是我的代码 public ArrayAdapter<String> adapter = null; friendFilter = (EditText) findViewById(R.id.friends_filter); friendList = (ListView) findVie
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);
我的适配器
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;
}
}
公共类FbFriendListAdapter扩展了ArrayAdapter{
公共静态FriendsGetProfilePics模型;
私有arraylistnameidpath;
私人语境;
位图图标;
Hashtable friendsImages;
公共FbFriendListAdapter(上下文c、ArrayList名称IDPath、列表FriendlistName){
super(c,R.layout.fb\u friend\u适配器,friendName);
this.nameIDPath=nameIDPath;
this.context=c;
if(model==null){
model=新的FriendsGetProfilePics();
}
model.setListener(this);
}
public int getCount(){
返回nameIDPath.size();
}
公共长getItemId(int位置){
返回位置;
}
静态类视窗夹{
公共文本视图持有者;
公众影像阅览排字架;
}
公共视图getView(int位置、视图转换视图、视图组父视图){
视窗座;
vh=新的视窗支架();
如果(convertview==null){
LayoutInflater inf=(LayoutInflater)context.getSystemService(context.LAYOUT\u INFLATER\u SERVICE);
convertview=inf.inflate(R.layout.fb\u friend\u适配器,null,true);
vh.descHolder=(TextView)convertview.findViewById(R.id.fbFriendName);
vh.typeHolder=(ImageView)convertview.findViewById(R.id.fbImage);
convertview.setTag(vh);
}否则{
vh=(ViewHolder)convertview.getTag();
}
String[]names=nameIDPath.get(position.toString().split(“@names”);
字符串[]idpath=names[1]。toString().split(@PATH”);
vh.descHolder.setText(名称[0]);
vh.typeHolder.setImageBitmap(model.getImage(idpath[0],idpath[1]);
返回视图;
}
}
请指导我。我找到了解决方案,实际上在适配器类中,我不需要重写getCount。方法getCount在我的案例中返回ArrayList的大小。因此,过滤器似乎不起作用。
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;
}
}