不同的按钮不同的上下文菜单?
Different button different context menu?
我有四个按钮,我想在这四个按钮上调用不同的上下文菜单,这适用于第一个按钮,如何对其他三个按钮实现相同类型的代码。我还尝试添加另一个按钮并在相同的覆盖方法中包含其他上下文菜单,还检查了网站,所以请告诉我怎么做。
@Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.semtosub);
sub1 = (Button) findViewById(R.id.subject1);
registerForContextMenu(sub1);
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v,ContextMenuInfo menuInfo) {
// TODO Auto-generated method stub
super.onCreateContextMenu(menu, v, menuInfo);
MenuInflater inflate = getMenuInflater();
inflate.inflate(R.menu.contexts1,menu);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch (item.getItemId()){
case R.id.chapter1:
Intent c1 = new Intent(Subject.this,Sub1C1.class);
startActivity(c1);
break;
case R.id.chapter2:
Intent c2 = new Intent(Subject.this,Sub1C2.class);
startActivity(c2);
break;
case R.id.chapter3:
Intent c3 = new Intent(Subject.this,Sub1C3.class);
startActivity(c3);
break;
case R.id.chapter4:
Intent c4 = new Intent(Subject.this,Sub1C4.class);
startActivity(c4);
break;
case R.id.chapter5:
Intent c5 = new Intent(Subject.this,Sub1C5.class);
startActivity(c5);
break;
}
return super.onContextItemSelected(item);
}
}
Run two or many activity on one button click?
使用 Context.startActivities,它在 Array 中接受多个意图并开始 Activity 一个接一个:
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i_one = new Intent (Semester.this,Subject.class);
Intent j_two = new Intent (Semester.this,Subject2.class);
startActivities(new Intent[]{i_one,j_two});
}
我有四个按钮,我想在这四个按钮上调用不同的上下文菜单,这适用于第一个按钮,如何对其他三个按钮实现相同类型的代码。我还尝试添加另一个按钮并在相同的覆盖方法中包含其他上下文菜单,还检查了网站,所以请告诉我怎么做。
@Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.semtosub);
sub1 = (Button) findViewById(R.id.subject1);
registerForContextMenu(sub1);
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v,ContextMenuInfo menuInfo) {
// TODO Auto-generated method stub
super.onCreateContextMenu(menu, v, menuInfo);
MenuInflater inflate = getMenuInflater();
inflate.inflate(R.menu.contexts1,menu);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch (item.getItemId()){
case R.id.chapter1:
Intent c1 = new Intent(Subject.this,Sub1C1.class);
startActivity(c1);
break;
case R.id.chapter2:
Intent c2 = new Intent(Subject.this,Sub1C2.class);
startActivity(c2);
break;
case R.id.chapter3:
Intent c3 = new Intent(Subject.this,Sub1C3.class);
startActivity(c3);
break;
case R.id.chapter4:
Intent c4 = new Intent(Subject.this,Sub1C4.class);
startActivity(c4);
break;
case R.id.chapter5:
Intent c5 = new Intent(Subject.this,Sub1C5.class);
startActivity(c5);
break;
}
return super.onContextItemSelected(item);
}
}
Run two or many activity on one button click?
使用 Context.startActivities,它在 Array 中接受多个意图并开始 Activity 一个接一个:
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i_one = new Intent (Semester.this,Subject.class);
Intent j_two = new Intent (Semester.this,Subject2.class);
startActivities(new Intent[]{i_one,j_two});
}