我正在尝试让ImageView
打开另一项活动:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gtacheats);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.gtacheats, menu);
return true;
ImageView Image1 = (ImageView) findViewById(R.id.Image1);
Image1.setClickable(true);
Image1.setOnClickListener(new View.OnClickListener() {
public void onClick(View V) {
Intent intent = new Intent(V.getContext(), Activity2.class);
startActivityForResult(intent, 0);
}
});
}
}
我做错了什么?它说“无法访问的代码”
答案 0 :(得分:1)
移动return true
作为onCreateOptionsMenu
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.gtacheats, menu);
ImageView Image1 = (ImageView) findViewById(R.id.Image1);
Image1.setClickable(true);
Image1.setOnClickListener(new View.OnClickListener() {
public void onClick(View V) {
Intent intent = new Intent(V.getContext(), Activity2.class);
startActivityForResult(intent, 0);
}
});
return true;
}