我正在尝试为我的应用实现搜索栏,我在empList.setAdapter(adapter)
下收到此错误
错误是error: cannot find symbol method setAdapter(ArrayAdapter<String>)
为什么会发生此错误,这就是方法的外观
public boolean onCreateOptionMenu(Menu menu){
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.menu, menu);
MenuItem menuItem = menu.findItem(R.id.search);
SearchView searchView = (SearchView) MenuItemCompat.getActionView(menuItem);
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener(){
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
ArrayList<String> empList = new ArrayList<>();
for (String emp : list){
if (emp.toLowerCase().contains(newText.toLowerCase())){
empList.add(emp);
}
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(ViewEmployee.this, android.R.layout.simple_list_item_1, empList);
empList.setAdapter(adapter);
return true;
}
});
return super.onCreateOptionsMenu(menu);
}