我需要在EditText的幫助下以分開的列表視圖執行搜索功能。我用edittext.addTextChangedListener()方法,我得到了解決方案。但EditText框只接受一個字符,當我試圖輸入第二個字符時它會導致關閉。如何在EditText的幫助下在分開的ListView中搜索?
我用下面的代碼。
edtSearch.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 cs, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
sAdapter.clear();
textlength = edtSearch.getText().length(); //getting text from EditText
Log.e("textlength",""+textlength);
array_name.clear(); array_friendid.clear(); array_status.clear(); array_image.clear();array_thumb.clear();
for (int i = 0; i < fullname.length; i++) {
if (textlength <= fullname[i].length()) {
if(edtSearch.getText().toString().equalsIgnoreCase((String)fullname[i].subSequence(0,textlength))) {
Log.e("arrayname",fullname[i]);
array_name.add(fullname[i]);
array_friendid.add(friendid[i]);
array_status.add(status[i]);
array_image.add(imageurl[i]);
array_thumb.add(thumbnailurl[i]);
array_header.add(fullname[i].substring(0, 1));
}
}
}
請發佈logcat消息... – Vinay