点击

时间:2017-01-06 06:58:07

标签: android listview

大家好我正在开发一个关于导入/导出和更新csv的应用程序,我有这个edittext过滤器。

当我选择它时,已存储项目的ID变为1。

以下是我的代码:

lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override

            public void onItemClick(AdapterView<?> parent, View view, int position, long id)
            {


                TextView cat;
                TextView code;
                TextView desc;
                TextView unit;
                TextView quan;



                Intent intent = new Intent(getApplicationContext(), Main2Activity.class);
                cat = (TextView) view.findViewById(R.id.txtproductcompany);
                String gory = cat.getText().toString();
                intent.putExtra(ID_EXTRA, gory);

                code = (TextView) view.findViewById(R.id.txtproductname);
                String deco = code.getText().toString();
                intent.putExtra(ID_EXTRA2, deco);

                desc = (TextView) view.findViewById(R.id.txtproductprice);
                String csed = desc.getText().toString();
                intent.putExtra(ID_EXTRA3, csed);

                unit = (TextView) view.findViewById(R.id.txtunit);
                String noti = unit.getText().toString();
                intent.putExtra(ID_EXTRA4, noti);

                quan = (TextView) view.findViewById(R.id.txtquan);
                String quanti = quan.getText().toString();
                intent.putExtra(ID_EXTRA5, quanti);

                intent.putExtra(ID_EXTRA1 , String.valueOf(id + 1));
                startActivity(intent);


                lv.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
                lv.setSelector(android.R.color.holo_blue_bright);


            }

        });

过滤搜索项目的代码:

search.addTextChangedListener(new TextWatcher() {

            @Override
            public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
                // When user changed the Text

                ((SimpleAdapter)MainActivity.this.adapter).getFilter().filter(cs);

            }

            @Override
            public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
                                          int arg3) {
                // TODO Auto-generated method stub

            }

            @Override
            public void afterTextChanged(Editable arg0) {
                // TODO Auto-generated method stub
            }
        });

1 个答案:

答案 0 :(得分:0)

您使用的ID是被点击的项目的行ID。如果你找到一条匹配的记录,那么当你找到一条匹配的记录时,你的id就是0,你就加1,所以你得到1