在我们的Andr​​oid应用搜索列表? [英] search list in our application in android?

查看:102
本文介绍了在我们的Andr​​oid应用搜索列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好我的应用程序有一个列表视图和搜索section.what我需要做的是,当我搜索,在搜索部的单词应该整理出相应的列表视图根据我search.i有话一个code排序的名字,但我真正的问题是,如果我需要寻找一个字,例如我需要搜索

  

Ramz超

这是我目前的codeI需要寻找像从研发,然后按照正确的顺序进行梳理。但我需要什么名称的等一个名字是从超级如果我开始搜索我需要显示名称 Ramz超在listview.how我能做到这一点我目前的搜索code是如下图

  search_sort.addTextChangedListener(新TextWatcher(){
        公共无效afterTextChanged(编辑S){
            // TextWatcher接口的抽象方法。
        }

        公共无效beforeTextChanged(CharSequence中,诠释开始,诠释计数,
                之后INT){
            // TextWatcher接口的抽象方法。
        }

        公共无效onTextChanged(CharSequence中,诠释开始,诠释之前,
                诠释计数){
            。=长度限制:Textlength search_sort.getText()长度();
            array_sort.clear();
            contactnumber_sort.clear();
            的for(int i = 0; I< contactname.size();我++){
                如果(长度限制:Textlength&其中; = contactname.get(ⅰ).length()){
                    如果(search_sort.getText()
                            的ToString()
                            .equalsIgnoreCase(
                                    (字符串)contactname.get(我).subSequence(
                                            0,长度限制:Textlength))){
                        array_sort.add(contactname.get(ⅰ));
                        contactnumber_sort.add(contactnumber.get(ⅰ));
                    }
                }
            }
            的System.out.println(array_sort);

            myadp =新myAdapter(MobiMailActivity.this,array_sort,co​​ntactnumber_sort);
            contactlist.setAdapter(myadp);
        }
    });
 

解决方案

尝试使用包含()而不是 equalsIgnoreCase()。凡 datasetList 是我的自定义的ArrayList和其中的对象; ContactList>

 公共无效onTextChanged(CharSequence中,诠释开始,诠释之前,诠释计数){
        // TODO自动生成方法存根
        。字符串getSearchString = search.getText()的toString();

        如果(datasetList =空&安培;!&安培; datasetList.size()大于0)
        {
            排序列表=新的ArrayList< ContactDataSet>(); //新的列表排序列表

            的for(int i = 0; I< datasetList.size();我++){

                如果(datasetList.get(ⅰ).getName()。包含(getSearchString)){
                    sortedList.add(datasetList.get(ⅰ));

                }
            }
        }
        adapter.setnewList(排序列表);
        lView.setAdapter(适配器);

    }
 

试试这个,让我know.It正在为me.Hope这可以帮助你。

Hi in my app there is a list view and a search section.what i need to do is when i search a word in the search section it should sort out the corresponding list view according to the word that i search.i got a code for sorting the name , but my real problem is if i need to search a word for example i need to search

Ramz super

which is a single name in my current code i need to search like from R then A etc in the correct order to sort out the name .But what i need is that if i start search from Super i need to show the name Ramz super in the listview.how can i do this my current search code is as shown below

    search_sort.addTextChangedListener(new TextWatcher() {
        public void afterTextChanged(Editable s) {
            // Abstract Method of TextWatcher Interface.
        }

        public void beforeTextChanged(CharSequence s, int start, int count,
                int after) {
            // Abstract Method of TextWatcher Interface.
        }

        public void onTextChanged(CharSequence s, int start, int before,
                int count) {
            textlength = search_sort.getText().length();
            array_sort.clear();
            contactnumber_sort.clear();
            for (int i = 0; i < contactname.size(); i++) {
                if (textlength <= contactname.get(i).length()) {
                    if (search_sort.getText()
                            .toString()
                            .equalsIgnoreCase(
                                    (String) contactname.get(i).subSequence(
                                            0, textlength))) {
                        array_sort.add(contactname.get(i));
                        contactnumber_sort.add(contactnumber.get(i));
                    }
                }
            }
            System.out.println(array_sort);

            myadp = new myAdapter(MobiMailActivity.this, array_sort, contactnumber_sort);
            contactlist.setAdapter(myadp);
        }
    });

解决方案

Try to use contains() instead of equalsIgnoreCase().Where datasetList is object of my custom ArrayList<ContactList>.

  public void onTextChanged(CharSequence s, int start, int before, int count) {
        // TODO Auto-generated method stub
        String getSearchString = search.getText().toString();

        if(datasetList != null && datasetList.size() > 0)
        {
            sortedList = new ArrayList<ContactDataSet>(); //new List sorted list 

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

                if (datasetList.get(i).getName().contains(getSearchString)) {
                    sortedList.add(datasetList.get(i));

                }
            }
        }           
        adapter.setnewList(sortedList);
        lView.setAdapter(adapter);

    }

Try this and let me know.It is working for me.Hope this helps you

这篇关于在我们的Andr​​oid应用搜索列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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