3
I have a listview with several items, I also have right up a searchView to perform a filter on these items, being they "clickable", starting another Activity.
The problem is that the numbering of lisView items changes according to what I search on searchView. That is, I can’t set an Activity for each listview item so that the Array items have an absolute position.Some 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 0 for the item Absolutism
I couldn’t get over the code formatting on the forum, sorry.
– Junior Klawa
The absolute position in relation to all items gives list?
– viana
This, for example, the first item in the array list will always be "0" is so on, so that it does not change position in Adapter. Since I use this number as a reference to open certain activities
– Junior Klawa