我们在android中输入第一个字母时未显示人员建议列表
在搜索选项中,在我们输入第一个字母时未显示用户建议列表。建议将显示在搜索栏中输入的第二个字母之后。是否有人给出此问题的可能解决方案我们在android中输入第一个字母时未显示人员建议列表,android,Android,在搜索选项中,在我们输入第一个字母时未显示用户建议列表。建议将显示在搜索栏中输入的第二个字母之后。是否有人给出此问题的可能解决方案 search.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { }
search.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
adapter.getFilter().filter(s, new Filter.FilterListener() {
public void onFilterComplete(int count) {
Log.d("log", "result count:" + count);
if (count == 0) {
usermsg.setText("No username found");
usermsg.setVisibility(View.VISIBLE);
peoplelist.setVisibility(View.GONE);
} else {
usermsg.setVisibility(View.GONE);
peoplelist.setVisibility(View.VISIBLE);
}
}
});
}
@Override
public void afterTextChanged(final Editable s) {
adapter.getFilter().filter(s, new Filter.FilterListener() {
public void onFilterComplete(int count) {
Log.d("log", "result count:" + count);
if (text.equals("people")) {
//movieList.clear();
getPeople();
if (count == 0) {
usermsg.setText("No username found");
usermsg.setVisibility(View.VISIBLE);
peoplelist.setVisibility(View.GONE);
} else {
usermsg.setVisibility(View.GONE);
peoplelist.setVisibility(View.VISIBLE);
}
} else if (text.equals("tag")) {
getTag(s);
usermsg.setText("# No Hash Tag found");
usermsg.setVisibility(View.VISIBLE);
peoplelist.setVisibility(View.GONE);
/*else {
usermsg.setVisibility(View.GONE);
peoplelist.setVisibility(View.VISIBLE);
}*/
}
}
});
}
});`
您必须维护两个
ARRAYLIST
,一个用于ListView
中的所有数据,另一个用于筛选数据
因此,在我下面的解决方案中,我有两个ArrayList
,一个用于所有名为FULL\u data\u ArrayList的数据,另一个用于FILTER\u ArrayList,因此plz引用了下面的解决方案:-
search.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (s.toString().length() == 0) {
usermsg.setText("No username found");
usermsg.setVisibility(View.VISIBLE);
adapter = new YOURADAPTERCLASS(YOUR_ACTIVITY.this, FULL_DATA_ARRAYLIST);
peoplelist.setAdapter(adapter);
} else {
usermsg.setVisibility(View.GONE);
peoplelist.setVisibility(View.VISIBLE);
FILTER_ARRAYLIST.clear();
for (int i = 0; i < FULL_DATA_ARRAYLIST.size(); i++) {
if (FULL_DATA_ARRAYLIST.get(i).getName().toLowerCase().contains(s.toString().toLowerCase()))
FILTER_ARRAYLIST.add(FULL_DATA_ARRAYLIST.get(i));
}
adapter = new YOURADAPTERCLASS(YOUR_ACTIVITY.this, FILTER_ARRAYLIST);
peoplelist.setAdapter(adapter);
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
search.addTextChangedListener(新的TextWatcher(){
@凌驾
更改前文本之前的公共void(字符序列s、int start、int count、int after){
}
@凌驾
public void onTextChanged(字符序列、int start、int before、int count){
如果(s.toString().length()==0){
usermsg.setText(“未找到用户名”);
usermsg.setVisibility(View.VISIBLE);
adapter=新的YOURADAPTERCLASS(您的\u ACTIVITY.this,完整的\u数据\u数组列表);
peoplelist.setAdapter(适配器);
}否则{
usermsg.setVisibility(View.GONE);
peoplelist.setVisibility(View.VISIBLE);
FILTER_ARRAYLIST.clear();
对于(int i=0;i
您可以在您的ContextChanged或PostTextChanged中执行操作…为什么要在edittext的addTextChangedListener方法的两种方法中执行操作…在edittext框中键入第一个字母时,我可以做些什么来显示人员列表您必须维护arraylist…一个用于所有数据,另一个用于来自筛选器的最短数据…..如果我键入第二个字母表示列表将显示如何创建筛选器数组listArrayList筛选器_ARRAYLIST=新建ARRAYLIST,则无法获得清晰的标识@苏里娅。。这对你有帮助吗,请接受它作为一个有用的答案:)我想,你在使用上述代码时犯了一些小错误..与我在我的应用程序中使用的代码相同,而且工作正常..无论如何,一切都很好..并保持愉快的coading