I have a menu and would like to open a new Activity when the user clicks on the menu item:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.add_symbol:
System.out.println("ADD SYMBOL CLICKED!");
Intent myIntent = new Intent(this.getContext(), AddStocksActivity.class);
startActivityForResult(myIntent, 0);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
I'm not sure how to create my Intent properly
Compiler Error:
The method getContext() is undefined for the type Main
In your activity class do
In your onCreate() do
then in your Options thing, do
Since
Main
extendsActivity
(which extendsContext
), you can do:this is what I do
}
hope it helps
or
Change
this.getContext()
tothis.getApplicationContext()
You are trying to call a method that doesn't exist.