Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/186.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 当我在主类中扩展活动时,如何使用基本适配器筛选列表项?_Android_Android Listview_Filtering - Fatal编程技术网

Android 当我在主类中扩展活动时,如何使用基本适配器筛选列表项?

Android 当我在主类中扩展活动时,如何使用基本适配器筛选列表项?,android,android-listview,filtering,Android,Android Listview,Filtering,在这里,我编写了一段代码,在其中我扩展了baseadapter,并设置了要在listview上显示的所有数据,我想从listview中搜索数据 public class Listadapter extends BaseAdapter { public Listadapter() { super(); } public int getCount() { return productList.size(); } publi

在这里,我编写了一段代码,在其中我扩展了baseadapter,并设置了要在listview上显示的所有数据,我想从listview中搜索数据

public class Listadapter extends BaseAdapter {

    public Listadapter() {
        super();
    }

    public int getCount() {
        return productList.size();
    }

    public long getItemId(int position) {
        return productList.indexOf(getItem(position));
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflator = ProductList.this.getLayoutInflater();

        TextView txtprodName, txtcategory, txtOfferDate;
        ImageView ProductImage;

            convertView = inflator.inflate(R.layout.product_list_item, null);                                   

            txtprodName = (TextView) convertView.findViewById(R.id.txtprodName);
            txtcategory = (TextView) convertView.findViewById(R.id.txtcategory);
            txtOfferDate = (TextView) convertView.findViewById(R.id.txtOfferDate);
            ProductImage = (ImageView) convertView.findViewById(R.id.ProductImage);

            HashMap<String, String> hm = productList.get(position);

        //txtUserName.setText(lstUsers.get(position).getFirst_Name()+" "+lstUsers.get(position).getLast_Name());
        txtprodName.setText(hm.get(TAG_PRODUCT_NAME));
        txtcategory.setText(hm.get(TAG_CATEGORY_NAME));
        txtOfferDate.setText(hm.get(TAG_OFFER_START_TIME));

        if(drawable.get(position)!=null)
            ProductImage.setImageDrawable(drawable.get(position));
        else
            ProductImage.setImageResource(R.drawable.nopic_place);

        return convertView;
    }

    @Override
    public Object getItem(int arg0) {
        // TODO Auto-generated method stub
        return null;
    }
}

您为什么不使用
ArrayAdapter
?它自动与综合过滤方法。我当然建议您使用此选项。但这会给baseadapter带来问题。这是因为您没有为适配器实现
Filterable
接口,使其能够实际使用
getFilter().filter
&
lstProductList.setAdapter(new Listadapter());

            inputSearch.addTextChangedListener(new TextWatcher() {

                @Override
                public void onTextChanged(CharSequence cs, int arg1,
                        int arg2, int arg3) {
                    // When user changed the Text
                    /*( (SimpleAdapter) lstProductList.getAdapter()).getFilter().filter(
                            cs);*/


                    }