0

在这里我正在编写代码,其中我扩展了 baseadapter,并且我已经设置了要在列表视图上显示的所有数据,我想从列表视图中搜索数据

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

现在如何在 OnTextChanged() 中调用 listadapter 进行过滤和搜索...我已经用简单的适配器做到了这一点..但它与 baseadapter 产生了问题

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);*/


                    }
4

0 回答 0