Estou com o seguinte problema, estou usando uma list view e um search view, e quando eu clico em um item, gostaria de abrir uma activity e mostrar um toast. Até ai tudo bem, quando eu pesquiso e clico no item 2 em vez de abrir a activity "2" do id "2" por exemplo ele abre a 1, pois o item 2 esta em primeiro na lista devido o resultado do search view. O meu toast está funcionando normalmente, apenas para abrir a activity estou com problemas.
MainActivity
public class MediaBall extends AppCompatActivity implements SearchView.OnQueryTextListener {
private SearchView mSearchView;
private ListView mListView;
private ArrayList<Pokemon1> employeeArrayList;
private PokemonAdapter1 employeeAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_media_ball);
mSearchView = (SearchView) findViewById(R.id.search15);
mListView = (ListView) findViewById(R.id.pokemons);
employeeArrayList = new ArrayList<Pokemon1>();
employeeArrayList.add(new Pokemon1("Bulbasaur", "#001", ));
employeeArrayList.add(new Pokemon1("Ivysaur", "#002", ));
employeeArrayList.add(new Pokemon1("Venosaur", "#003", ));
employeeAdapter=new PokemonAdapter1(MediaBall.this, employeeArrayList);
mListView.setAdapter(employeeAdapter);
mListView.setTextFilterEnabled(true);
setupSearchView();
registerClickCallback();
}
private void registerClickCallback() {
ListView list = (ListView) findViewById(R.id.pokemons);
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// Pokemon1 pick = employeeArrayList.get(position);
Pokemon1 pick = (Pokemon1) employeeAdapter.getItem(position);
String message = "You Selected " + pick.getName();
if (position == 0)
{
Intent myIntent1 = new Intent(view.getContext(), IvysaurActivity.class);
myIntent.putExtra("position", position);
startActivityForResult(myIntent1, 0);
}
if (position == 1)
{
Intent myIntent1 = new Intent(view.getContext(), VenusaurActivity.class);
startActivityForResult(myIntent1, 0);
}
if (position == 3)
{
Intent myIntent1 = new Intent(view.getContext(), BulbasaurActivity.class);
startActivityForResult(myIntent1, 0);
}
Toast.makeText(MediaBall.this, message, Toast.LENGTH_SHORT).show();
}
});
}
private void setupSearchView()
{
mSearchView.setIconifiedByDefault(false);
mSearchView.setOnQueryTextListener(this);
mSearchView.setSubmitButtonEnabled(true);
mSearchView.setQueryHint("Pesquise Aqui!!");
}
@Override
public boolean onQueryTextChange(String newText)
{
if (TextUtils.isEmpty(newText)) {
mListView.clearTextFilter();
} else {
mListView.setFilterText(newText);
}
return true;
}
@Override
public boolean onQueryTextSubmit(String query)
{
return false;
}
}
Desde já grato.