如何在我的代码中过滤自定义列表视图

时间:2014-07-20 20:54:01

标签: android listview filter

我搜索了我的问题几个小时但没有找到完美的解决方案。我有一个自定义列表视图,我想使用edittext过滤listview项目,请帮助我的代码将过滤器添加到listview。 这是我自定义列表视图的代码:

        protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
         setListAdapter(new MyAdapter(this, android.R.layout.simple_list_item_1,R.id.title,str)      
      }
    public class MyAdapter extends ArrayAdapter<String>{

    public MyAdapter(Context context, int resource, int textViewResourceId,
            String[] strings) {
        super(context, resource, textViewResourceId, strings);
        // TODO Auto-generated constructor stub

    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater=(LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View row=inflater.inflate(R.layout.item_layout, parent, false);
        String[] items=getResources().getStringArray(R.array.countries);
        TextView tv=(TextView) row.findViewById(R.id.title);
        ImageView iv=(ImageView) row.findViewById(R.id.list_image);
        TextView dtv=(TextView) row.findViewById(R.id.artist);
        ImageView iv_like=(ImageView) row.findViewById(R.id.img_like);
        tv.setText(items[position]);
       EditText ed=(EditText) findViewById(R.id.search);
        if(items[position].equals("برترین ها"))
        {
            if(checkBoxValue0)
                iv_like.setImageResource(R.drawable.star_on_final);
                iv.setImageResource(R.drawable.list_great_messi);
                dtv.setText(R.string.en_g10);
        }
        else if(items[position].equals("خوش قیافه ترین ها"))
        {
            if(checkBoxValue1)
                iv_like.setImageResource(R.drawable.like_ball);
            iv.setImageResource(R.drawable.list_handsome_kaka);
            dtv.setText(R.string.en_handsome);
        }
        else if(items[position].equals("ثروتمندترین ها"))
        {
            if(checkBoxValue2)
                iv_like.setImageResource(R.drawable.like_braz);
            iv.setImageResource(R.drawable.list_rich_ronaldo);
            dtv.setText(R.string.en_rich);
        }
        return row;
    }

}

0 个答案:

没有答案