Android:Searchview只搜索整个单词

时间:2013-12-31 10:16:32

标签: android searchview

搜索基于起始字符,但我希望它会搜索所有内容。 这是我的代码的一部分,方法onTextChanged不对,我想..感谢您的帮助!

@Override
public void onCreate(Bundle savedInstanceState) {

    final ArrayList<String> seznamPojmov = (ArrayList<String>) SeznamPojmovRazlag(0); 
    final ArrayList<String> array_sort= new ArrayList<String>();
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_slovar);

    final ListView list = (ListView) findViewById(R.id.slovar);
    final EditText iskanje = (EditText) findViewById(R.id.iskanje);

    final ArrayAdapter a = new ArrayAdapter<String (this,android.R.layout.simple_list_item_1, seznamPojmov);
    list.setAdapter(a);
    iskanje.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)
        {
            int len=0;
            len = iskanje.getText().length();
            array_sort.clear();
            for (int i = 0; i < seznamPojmov.size(); i++)
            {
                if (len <= seznamPojmov.get(i).length())
                {
            if(iskanje.getText().toString().equalsIgnoreCase((String)seznamPojmov.get(i).subSequence(0,len)))
                    {
                        array_sort.add(seznamPojmov.get(i));
                        }
                    }
                }
            list.setAdapter(new ArrayAdapter<String> (Slovar.this, android.R.layout.simple_list_item_1, array_sort));
            }
    });

1 个答案:

答案 0 :(得分:0)

像这样使用contains()方法

替换

 if(iskanje.getText().toString().equalsIgnoreCase((String)seznamPojmov.get(i).subSequence(0,len)))

 if((boolean)seznamPojmov.get(i).contains(iskanje.getText().toString()))