ListView两次填充相同的数据?

时间:2016-05-09 08:32:13

标签: java android listview

我有一个列表视图,它根据文本更改显示数据。但是我得到两次显示相同的数据。例如,如果我的列表包含一个“apple”,则列表将包含两个apple。即两次相同的条目。

这是我的代码: -

 private void showDocno(String response) {
    ParseAdvOpen pao = new ParseAdvOpen(response);
    pao.parseJSON();
    List<Map<String, String>> dn_info = new ArrayList<Map<String, String>>();
    Map<String, String> dn_map;
    int counts = ParseAdvOpen.adv_no.length;
    for (int i = 0; i < counts; ++i) {
        dn_map = new HashMap<>();
        dn_map.put("doc_no", ParseAdvOpen.adv_no[i]);
        dn_map.put("date", ParseAdvOpen.date[i]);
        dn_map.put("cust_name", ParseAdvOpen.cust_name[i]);
        dn_map.put("cust_number", ParseAdvOpen.cust_number[i]);
        dn_map.put("item_count", ParseAdvOpen.item_count[i]);
        dn_map.put("total", ParseAdvOpen.sum_total[i]);
        dn_map.put("paid", ParseAdvOpen.paid[i]);
        dn_info.add(dn_map);
    }

    dnAdapter = new SimpleAdapter(getActivity().getApplicationContext(), dn_info, R.layout.list_docno, new String[]{"doc_no", "cust_name", "cust_number"}, new int[]{R.id.textViewdn, R.id.customer_name, R.id.customer_mobile});
    doc_list.setAdapter(dnAdapter);
    Log.d("DNINFO", dn_info.toString());

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

            doc_list.setVisibility(View.INVISIBLE);
            advopen_list.setVisibility(View.VISIBLE);
            searchlayout.setVisibility(View.GONE);

        }

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

            doc_list.setVisibility(View.VISIBLE);
        }

        @Override
        public void afterTextChanged(Editable s) {
            if (s.length() == 0) {
                doc_list.setVisibility(View.INVISIBLE);
            } else {
                dnAdapter.getFilter().filter(s);
                doc_list.setVisibility(View.VISIBLE);

            }

        }
    });

    doc_list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Map docSelected = (Map) dnAdapter.getItem(position);
            String doc_number = (String) docSelected.get("doc_no");
            String date = (String) docSelected.get("date");
            String customerName = (String) docSelected.get("cust_name");
            String mobileno = (String) docSelected.get("cust_number");
            String icount = (String) docSelected.get("item_count");
            String total = (String) docSelected.get("total");
            String paid = (String) docSelected.get("paid");


            Log.d("DOCUMENT SELECTED", doc_number + " " + customerName + " " + mobileno + " " + date);
            advopen_list.setVisibility(View.GONE);
            doc_list.setVisibility(View.GONE);
            searchlayout.setVisibility(View.VISIBLE);
            tv_docno.setText(doc_number);
            tv_date.setText(date);
            tv_name.setText(customerName);
            tv_mobile.setText(mobileno);
            tv_itemcount.setText(icount);
            tv_tot.setText(total);
            tv_paid.setText(paid);


        }
    });


}

这个方法在对mysql数据库的响应中被调用。

感谢任何帮助或建议。谢谢。

0 个答案:

没有答案