searchview acitonbar 위젯을 사용하여 목록보기를 필터링하려고하는데 edittext에 뭔가를 입력하면 검정 상자가 화면에 나타납니다. 그 블랙 박스없이 검색하는 법. SearchView 위젯이 제대로 작동하지 않습니다.
여기 내 코드입니다. 이렇게하려면 목록보기를 설정하기 때문에
public class MainActivity extends ListActivity implements OnQueryTextListener{
private Button favListBtn;
private ListView mListView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String[] categories = {"Food", "Cloth", "Shoes","Agriculture",
"Food", "Cloth", "Shoes","Agriculture",
"Food", "Cloth", "Shoes","Agriculture",
"Food", "Cloth", "Shoes","Agriculture",
"Food", "Cloth", "Shoes","Agriculture",
"Food", "Cloth", "Shoes","Agriculture",
"Food", "Cloth", "Shoes","Agriculture"};
mListView = (ListView) findViewById(android.R.id.list);
mListView = getListView();
ArrayAdapter<String> mAdapte = new ArrayAdapter<String>(MainActivity.this,
android.R.layout.simple_list_item_1, categories);
mListView.setAdapter(mAdapte);
mListView.setTextFilterEnabled(true);
mListView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
new SearchAsynTask(MainActivity.this).execute();
// selected item
String category = ((TextView) view).getText().toString();
Intent intent = new Intent(MainActivity.this, BusinessListActivity.class);
startActivity(intent);
Toast.makeText(MainActivity.this, category, Toast.LENGTH_LONG).show();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
searchView.setSubmitButtonEnabled(true);
searchView.setOnQueryTextListener(this);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}
@Override
public boolean onQueryTextChange(String query) {
if (TextUtils.isEmpty(query))
{
mListView.clearTextFilter();
}
else
{
mListView.setFilterText(query.toString());
}
return true;
}
}
후 일부 코드 :
그런 다음 당신은 Filter 개체의 검색을 수행한다! –
@Tim 제 질문을 업데이트했습니다. – FAISAL
나는 그것이 당신 때문이라고 생각한다. Toast.makeText (MainActivity.this, category, Toast.LENGTH_LONG) .show(); – Cjames