我添加了textBox到我的應用程序來過濾ListView項目,所以當我在文本框中鍵入文本時,它通常過濾,但是當我嘗試選擇過濾項目時,它會打開原始位置的活動在過濾器之前而不是過濾後的過濾器上。我的過濾列表項目打開錯誤活動
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AdView mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
inputSearch = (EditText) findViewById(R.id.inputSearch);
String[] ciwaananadaGabayada = getResources().getStringArray(R.array.gabayada_array);
mListView = (ListView) findViewById(R.id.listView1);
// Adding items to listview
adapter = new ArrayAdapter<String>(this, R.layout.list_item, R.id.gabay_item, ciwaananadaGabayada);
mListView.setAdapter(adapter);
mListView.setTextFilterEnabled(true);
//Enabling Search Filter
inputSearch.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
// When user changed the text
MainActivity.this.adapter.getFilter().filter(charSequence);
adapter.notifyDataSetChanged();
//adapter.getFilter().filter(charSequence);
}
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void afterTextChanged(Editable editable) {
}
});
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
switch (position) {
case 0:
Intent newActivity = new Intent(MainActivity.this, Xuseenow_caqligu.class);
startActivity(newActivity);
break;
case 1:
Intent newActivity1 = new Intent(getApplicationContext(), dhurwaa_adhiga.class);
startActivity(newActivity1);
break;
case 2:
Intent newActivity2 = new Intent(getApplicationContext(), xuseenowAqoonXume.class);
startActivity(newActivity2);
break;
把你的適配器類 –
@CoDFather我在哪裏把我的適配器類 – Suhayb
把它放在這裏! –