Фильтрация ArrayAdapter ListView с изображением - PullRequest
1 голос
/ 14 декабря 2011

У меня проблема с фильтрацией моего списка и не могу найти хорошего примера для моей ситуации. На самом деле мой список - это список моего друга в фейсбуке вместе с изображением. Мой класс - это занятие, которое реализует средство просмотра текста, а ниже - мой код.

    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 включен,

    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;
    }   
}

Пожалуйста, ведите меня.

...