Android Search Not Opening Activities
i have implemented search functionality in my app, but whenever i pick an item from the search results, it won't launch the picked activity .according to the code , if i click on s
Solution 1:
Change onItemClick to
publicvoidonItemClick(AdapterView<?> parent, View view,
int position, long id){
Intent myIntent = newIntent(MainActivity.this,Next.class);
startActivity(myIntent);
// will launch activity every time an item in listview is clicked
}
});
You have this
if (position == 1) // only if position is 1
{
Intent myIntent = newIntent(getApplicationContext(),Next.class);
startActivity(myIntent);
}
Use activity context instead of getApplicationContext as MainActivity.this
Edit:
publicvoidonItemClick(AdapterView<?> parent, View view,
int position, long id){
if(position==0)
{
Intent myIntent = newIntent(MainActivity.this,Next.class);
startActivity(myIntent);
}
if(position==1)
{
Intent myIntent = newIntent(MainActivity.this,SecondActivityName.class);
startActivity(myIntent);
}
...// similar position 2 and 3 and so on
}
});
Solution 2:
You code will work on only the item at 1st position because you have done this in your listview item click listener :-
if (position == 1)
{
Intent myIntent = newIntent(getApplicationContext(),Next.class);
startActivity(myIntent);
}
only on the click on the item at 1st position, this if condition will come true and "Next" activity will be called
Post a Comment for "Android Search Not Opening Activities"