I have a listView with several items, I also have a searchView to make a filter on these items, being "clickable", starting another Activity.
The problem is that the numbering of lisView items changes according to what I search in searchView. That is, I can not set an Activity for each listView item so that Array items have an absolute position. Any light?
Here's the code in question.
ListView lv;
SearchView sv;
String[] teams={"Absolutismo",
"Agentes de Relevo",
"Alelobiose",
"Alta Idade Média",
"América",
};
ArrayAdapter<String> adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tela_pesquisa);
lv=(ListView) findViewById(R.id.listView);
sv=(SearchView) findViewById(R.id.searchView);
adapter=new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,teams);
lv.setAdapter(adapter);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
int itemPosition = position;
// ListView Clicked item value
String itemValue = (String) lv.getItemAtPosition(position);
// Show Alert
Toast.makeText(getApplicationContext(), "Position :"+itemPosition+" ListItem : " +itemValue , Toast.LENGTH_LONG).show();
switch( position )
{
case 0: Intent newActivity = new Intent(telaPesquisa.this, historiaAbsolutismo.class);
startActivity(newActivity);
break;
case 1: Intent newActivityy = new Intent(telaPesquisa.this, geografiaAgentesFormadoresDeRelevo.class);
startActivity(newActivityy);
break;
case 2: Intent newActivity2 = new Intent(telaPesquisa.this, biologiaAlelobioses.class);
startActivity(newActivity2);
break;
case 3: Intent newActivity3 = new Intent(telaPesquisa.this, historiaAltaIdadeMedia.class);
startActivity(newActivity3);
break;
case 4: Intent newActivity4 = new Intent(telaPesquisa.this, geografiaAmerica.class);
startActivity(newActivity4);
break;
}
}
});
sv.setOnQueryTextListener(new OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String text) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean onQueryTextChange(String text) {
adapter.getFilter().filter(text);
return false;
}
});
}
}
Here the' position 'is at 0 for the item Absolutism