我有一个菜单,希望当用户点击菜单项时能够打开一个新的活动:
@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);
}
}
我不确定如何正确创建我的Intent。
编译器错误:
The method getContext() is undefined for the type Main