I\'m new to the android development and having a bit of a problem changing activities. I am trying to change activities from within a method but I am getting the error can
You should use the context of your adapter:
public void open301(View view) {
Intent openThree = new Intent(context,ThreeZeroOne.class);
context.startActivity(openThree);
}
To start a new activity you will need a context to start from, and your current activity "BaseAdapter" is not a Context, luckly every view has a Context, so you can do like this:
public void open301(View view) {
Intent openThree = new Intent(view.getContext(), ThreeZeroOne.class);
view.getContext().startActivity(openThree);
}
First you should get your Context
:
private Context context;
public CustomAdapter(Context context) {
this.context = context;
}
And then:
context.startActivity(openThree);
you can also pass messages
Intent i = new Intent( getContext(),Chat.class);
i.putExtra("id",user.id);
i.putExtra("name",user.name);
getContext().startActivity(i);