HelloI为我的片段添加了搜索edittext但是我得到了这个错误无法解析方法getFilter() 我如何使用它来搜索这样的列表视图?如何在edittext中添加图标 通过单击一个字母,只显示以此字母开头的项目
ComboBox
xml代码 如何将图标添加到edittext
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootview = inflater.inflate(R.layout.fragment_user, container, false);
listView = (ListView) rootview.findViewById(R.id.listView);
inputSearch = (EditText) rootview.findViewById(R.id.inputSearch);
listView.setOnItemClickListener(this);
getJSON();
inputSearch.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
UserFragment.this.adapter.getFilter().filter(cs);
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
}
@Override
public void afterTextChanged(Editable arg0) {
}
});
return rootview;
}
private void Display(){
JSONObject jsonObject = null;
ArrayList<HashMap<String,String>> list = new ArrayList<HashMap<String, String>>();
try {
jsonObject = new JSONObject(JSON_STRING);
JSONArray result = jsonObject.getJSONArray(TAG_JSON_ARRAY);
for(int i = 0; i<result.length(); i++){
JSONObject jo = result.getJSONObject(i);
String name = jo.getString("Nom");
String email = jo.getString("Email");
String login = jo.getString("Login");
HashMap<String,String> users= new HashMap<>();
users.put("name",name);
users.put("email",email);
users.put("login",login);
list.add(users);
}
} catch (JSONException e) {
e.printStackTrace();
}
ListAdapter adapter = new SimpleAdapter(
getActivity(), list, R.layout.list_row,
new String[]{"name","email"},
new int[]{R.id.nom, R.id.email2});
listView.setAdapter(adapter);
}
我需要你的帮助 提前谢谢
答案 0 :(得分:0)
您可以使用
android:drawableEnd="@drawable/view"
在您的编辑文字中添加图标。
您可以通过在edittext上添加TextView.OnEditorActionListener来搜索listview。
例:
myEditText.setOnEditorActionListener(new OnEditorActionListener(){
@覆盖
public boolean onEditorAction(TextView v,int actionId,KeyEvent event){
//做一些事情
}
});