Java 在android的自定义列表视图中仅搜索特定值的结果?

Java 在android的自定义列表视图中仅搜索特定值的结果?,java,android,android-arrayadapter,Java,Android,Android Arrayadapter,我使用的是自定义列表视图,我想搜索一个特定的值。现在我想我的代码搜索的是与输入的文本匹配的任何内容。我只想搜索文档号。 下面是我的代码 public void showJson(String json) { final Context billsctx = getActivity(); ParseBills pb = new ParseBills(json); pb.parseJSON(); bl = new BillsCu

我使用的是自定义列表视图,我想搜索一个特定的值。现在我想我的代码搜索的是与输入的文本匹配的任何内容。我只想搜索文档号。 下面是我的代码

   public void showJson(String json) {
        final Context billsctx = getActivity();
        ParseBills pb = new ParseBills(json);
        pb.parseJSON();

        bl = new BillsCustomList((Activity) billsctx, ParseBills.doc_no, ParseBills.date, ParseBills.cust_name, ParseBills.cust_number, ParseBills.item_count, ParseBills.total_wt,
                ParseBills.total,ParseBills.balance, ParseBills.bill_type);


        all_listView.setAdapter(bl);




        inputSearch.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {


                    bl.getFilter().filter(s);

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {

                if (s.length()==0)
                {
                    refreshFragment();
                }

            }
        });
}

这是我的适配器代码

public class BillsCustomList extends ArrayAdapter<String>
{
    private String[] doc_no;
    private String[]date;
    private String[] cust_name;
    private String[] cust_number;
    private String[] item_count;
    private String[]total_wt;
    private String[]total;
    private String[]balance;
    private String[]bill_type;

    private Activity context;

    public BillsCustomList(Activity context, String[] doc_no, String[] date, String[] cust_name,String[] cust_number,String[] item_count,String[] total_wt,String[] total,String[] balance,String[] bill_type)
    {
        super(context, R.layout.bills_list_view, doc_no);
        this.context =context;
        this.doc_no=doc_no;
        this.date = date;
        this.cust_name = cust_name;
        this.cust_number = cust_number;
        this.item_count= item_count;
        this.total_wt = total_wt;
        this.total = total;
        this.balance = balance;
        this.bill_type = bill_type;

    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        LayoutInflater inflater = context.getLayoutInflater();
        View listViewItem = inflater.inflate(R.layout.bills_list_view, null, true);
        TextView textViewDocno = (TextView) listViewItem.findViewById(R.id.textViewInvNo);
        TextView textViewDt = (TextView) listViewItem.findViewById(R.id.textViewDt);
        TextView textViewName = (TextView) listViewItem.findViewById(R.id.textViewName);
        TextView textViewNumber = (TextView) listViewItem.findViewById(R.id.textViewNumber);
        TextView textViewCount = (TextView) listViewItem.findViewById(R.id.textViewCount);
        TextView textViewTotwt = (TextView) listViewItem.findViewById(R.id.textViewTotwt);
        TextView textViewTot = (TextView) listViewItem.findViewById(R.id.textViewTot);
        TextView textViewBal = (TextView) listViewItem.findViewById(R.id.textViewBalanace);
        TextView textViewBt = (TextView) listViewItem.findViewById(R.id.textViewBt);

        textViewDocno.setText(doc_no[position]);
        textViewDt.setText(date[position]);
        textViewName.setText(cust_name[position]);
        textViewNumber.setText(cust_number[position]);
        textViewCount.setText(item_count[position]);
        textViewTotwt.setText(total_wt[position]);
        textViewTot.setText(total[position]);
        textViewBal.setText(balance[position]);
        textViewBt.setText(bill_type[position]);

        return listViewItem;
    }
}
公共类BillsCustomList扩展了ArrayAdapter
{
私有字符串[]文档编号;
私有字符串[]日期;
私有字符串[]客户名称;
私有字符串[]客户编号;
私有字符串[]项计数;
私有字符串[]总重量;
私有字符串[]总计;
私人字符串[]余额;
专用字符串[]票据类型;
私人活动语境;
公共账单列表(活动上下文,字符串[]单据号,字符串[]日期,字符串[]客户名称,字符串[]客户编号,字符串[]项目计数,字符串[]总计,字符串[]余额,字符串[]账单类型)
{
super(上下文、右布局、账单列表视图、单据号);
this.context=上下文;
this.doc\u no=doc\u no;
this.date=日期;
this.cust\u name=cust\u name;
this.cust_number=cust_number;
此项。项目计数=项目计数;
this.total_wt=total_wt;
这个.总计=总计;
这个平衡=平衡;
this.bill\u type=bill\u type;
}
@凌驾
公共视图getView(int位置、视图转换视图、视图组父视图)
{
LayoutInflater充气器=上下文。getLayoutInflater();
View listViewItem=充气机。充气(R.layout.bills\u list\u视图,null,true);
TextView textViewDocno=(TextView)listViewItem.findViewById(R.id.textViewInvNo);
TextView textViewDt=(TextView)listViewItem.findViewById(R.id.textViewDt);
TextView textViewName=(TextView)listViewItem.findViewById(R.id.textViewName);
TextView textViewNumber=(TextView)listViewItem.findViewById(R.id.textViewNumber);
TextView textViewCount=(TextView)listViewItem.findViewById(R.id.textViewCount);
TextView textViewTotwt=(TextView)listViewItem.findViewById(R.id.textViewTotwt);
TextView textViewTot=(TextView)listViewItem.findViewById(R.id.textViewTot);
TextView textViewBal=(TextView)listViewItem.findViewById(R.id.textViewBalanace);
TextView textViewBt=(TextView)listViewItem.findViewById(R.id.textViewBt);
textViewDocno.setText(文件编号[位置]);
text视图dt.setText(日期[位置]);
textViewName.setText(客户名称[职位]);
textViewNumber.setText(客户编号[位置]);
textViewCount.setText(项目计数[位置]);
textViewTotwt.setText(总重量[位置]);
textViewTot.setText(总[位置]);
text视图bal.setText(平衡[位置]);
text视图bt.setText(票据类型[位置]);
返回listViewItem;
}
}

任何建议或帮助都将不胜感激。谢谢。

尝试使用以下自定义过滤器:

 @Override
public Filter getFilter() {
    Filter filter=new Filter() {
        @Override
        protected FilterResults performFiltering(CharSequence constraint) {
           FilterResults results=new FilterResults();
            if(constraint!=null)
            {
              places=getPredictions(constraint.toString());
                if(places!=null)
                {
                    results.values=places;
                    results.count=places.size();
                }
            }
            return results;
        }
        @Override
        protected void publishResults(CharSequence constraint, FilterResults results) {
            if (results != null && results.count > 0) {
                // The API returned at least one result, update the data.
                notifyDataSetChanged();
            } else {
                // The API did not return any results, invalidate the data set.
                notifyDataSetInvalidated();
            }
        }
    };
    return filter;
}

此示例来自:-但您可以尝试根据需要修改它。谢谢希望对您有所帮助

尝试使用以下自定义过滤器:

 @Override
public Filter getFilter() {
    Filter filter=new Filter() {
        @Override
        protected FilterResults performFiltering(CharSequence constraint) {
           FilterResults results=new FilterResults();
            if(constraint!=null)
            {
              places=getPredictions(constraint.toString());
                if(places!=null)
                {
                    results.values=places;
                    results.count=places.size();
                }
            }
            return results;
        }
        @Override
        protected void publishResults(CharSequence constraint, FilterResults results) {
            if (results != null && results.count > 0) {
                // The API returned at least one result, update the data.
                notifyDataSetChanged();
            } else {
                // The API did not return any results, invalidate the data set.
                notifyDataSetInvalidated();
            }
        }
    };
    return filter;
}
此示例来自:-但您可以尝试根据需要修改它。谢谢希望它有帮助

试试下面的代码

 ArrayList<String> type_name_copy = new ArrayList<String>();

 inputSearch.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence s, int start, int before,
                int count) {
           ArrayList<String> type_name_filter = new ArrayList<String>();

            String text = theWatchedText.toString();

            for (int i = 0; i < array.size(); i++) {

                if ((ParseBills.doc_no[i].toLowerCase()).contains(text
                        .toLowerCase())) {
                    type_name_filter.add(ParseBills.doc_no[i]);

                }
            }

            type_name_copy = type_name_filter;//use this to update list


        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count,
                int after) {
        }

        @Override
        public void afterTextChanged(Editable theWatchedText) {

        }
    });
ArrayList type\u name\u copy=new ArrayList();
inputSearch.addTextChangedListener(新的TextWatcher(){
@凌驾
public void onTextChanged(字符序列,int start,int before,
整数计数){
ArrayList type_name_filter=新建ArrayList();
String text=theWatchedText.toString();
对于(int i=0;i
尝试下面的代码

 ArrayList<String> type_name_copy = new ArrayList<String>();

 inputSearch.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence s, int start, int before,
                int count) {
           ArrayList<String> type_name_filter = new ArrayList<String>();

            String text = theWatchedText.toString();

            for (int i = 0; i < array.size(); i++) {

                if ((ParseBills.doc_no[i].toLowerCase()).contains(text
                        .toLowerCase())) {
                    type_name_filter.add(ParseBills.doc_no[i]);

                }
            }

            type_name_copy = type_name_filter;//use this to update list


        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count,
                int after) {
        }

        @Override
        public void afterTextChanged(Editable theWatchedText) {

        }
    });
ArrayList type\u name\u copy=new ArrayList();
inputSearch.addTextChangedListener(新的TextWatcher(){
@凌驾
public void onTextChanged(字符序列,int start,int before,
整数计数){
ArrayList type_name_filter=新建ArrayList();
String text=theWatchedText.toString();
对于(int i=0;i
refreshFragment()做什么?@user3295583 refreshFragment()刷新列表视图。refreshFragment()做什么?@user3295583 refreshFragment()刷新列表视图。