简体   繁体   English

将过滤器添加到具有两个textview的listview

[英]Add filter to listview with two textview

I have a custom ListView with two TexView , I fill it with a SimpleAdapter with this code below 我有一个带有两个TexView的自定义ListView ,我用下面的代码用SimpleAdapter填充它

adapter = new SimpleAdapter(this, list,
            R.layout.activity_lista_vehiculo,
            new String[] { "value1","value2" },
            new int[] {R.id.line_a, R.id.line_b});      
    setListAdapter( adapter );

How can i put a filter to it from an EditText or SearchView ? 如何从EditTextSearchView对其添加过滤器?

SimpleAdapter has a build-in SimpleFilter which filters the content of your ListView adapter with a prefix. SimpleAdapter具有内置的SimpleFilter ,可使用前缀过滤ListView adapter的内容。 If this is what you want, you can use the following code to do the filter work: 如果这是您想要的,则可以使用以下代码来完成过滤器工作:

            yourEditText.addTextChangedListener(new TextWatcher() {

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

                }

                @Override
                public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
                        int arg3) {

                }

                @Override
                public void afterTextChanged(Editable arg0) {

                }
            });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM