在列表视图android中的自定义过滤 [英] Custom Filtering in listview android

查看:61
本文介绍了在列表视图android中的自定义过滤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Android的新手,我有一个包含某些项目的Listview,每个项目包含大小为20个字符的字符串(第一个字符至第16个字符相同).我必须在列表视图中添加搜索选项,以便,取决于最后4个字符,只应过滤列表.我看过很多网站,但找不到.

I am a new to Android,I have a Listview with some items, each item contains string of size 20 characters(1st character to 16th character are same).I have to add search option to list view in such a way that,depending on last 4 characters only the list should filter. I have seen many sites but i couldn't find.

例如:
清单项目:123456789ABCD1
清单项目:123456789EFGH2
清单项目:123456789IJKL3
列表项:123456789MNOP4

ex:
list items : 123456789ABCD1
list items : 123456789EFGH2
list items : 123456789IJKL3
list items : 123456789MNOP4

如果我使用

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

}

@Override
public void beforeTextChanged(CharSequence s, int start, int count,
        int after) {
    // TODO Auto-generated method stub

}

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




    myAdapter.getFilter().filter(s.toString());

}

我应该输入
123456789A在Edittext中,然后仅过滤器出现在列表视图中

i should enter
123456789A in Edittext then only filter occur in listview

我的要求是
我应该进入Edittext中的AB,以便它开始过滤

My requirement is
i should enter AB in Edittext so that it starts filtering

对于您的想法,我将不胜感激.预先感谢

I would appreciate for your ideas. Thanks in advance

推荐答案

您可以通过两种方式来实现.

You can do it in two ways.

1)对列表中的数组数据应用过滤器,为此目的,请使用 String.Contains()方法.

1) apply filter on the array data you have in list vie , Use String.Contains() method for this purpose.

示例:- ListArray [i] .toString.contains(SearchString); //如果存在搜索字符串,它将返回true.

Example :- ListArray[i].toString.contains(SearchString); // it will return true if search string is present.

2)如果将列表数据保存到Sqlite数据库中.您可以运行如下查询

2)If you hold list data into Sqlite database. You can run a query like below

示例:- sqliteDatabaseObj.Query(TABLE_NAME,null,COLUMN_NAME +如%" + searchString%",null,null);

这是该列表数据过滤的示例

P.S:-我写的例子在语法上是不正确的.请检查文档并使用它们,

P.S:- Examples i written are not syntactically correct. Please check the docs and use them,

这篇关于在列表视图android中的自定义过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆