我在操作栏中有一个菜单,所以我希望在每种情况下都能打开一个活动。我无法弄清楚如何做到这一点。我的第一个活动是关于我们(只是一个文本视图)
<div class="main">
<div class="child1">Block 1</div>
<div class="child2">Block 2!</div>
<div class="child3">Block 3</div>
<div class="child4">Block 4</div>
</div>
答案 0 :(得分:0)
您可以将您的意图传递给您想要打开的课程。
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Intent intent;
switch(item.getItemId()) {
case R.id.about_us:
//open AboutUsActivity
intent = new Intent(this, aboutUsActivity.class);
startActivity(intent);
finish();
return true;
case R.id.about_measures:
//add the function to perform here
intent = new Intent(this, aboutMeasuresActivity.class);
startActivity(intent);
finish();
return true;
case R.id.feedback:
//add the function to perform here
intent = new Intent(this, feedbackActivity.class);
startActivity(intent);
finish();
return true;
case R.id.rate:
//add the function to perform here
intent = new Intent(this, rateActivity.class);
startActivity(intent);
finish();
return true;
}
return(super.onOptionsItemSelected(item));
}
答案 1 :(得分:0)
您需要提供指定目标活动和当前活动上下文的意图。像这样:
case R.id.about_us:
//open AboutUsActivity
startActivity(new Intent(CurrentActivity.this, AboutUsActivity.class));
return(true);