我有一个包含 5 个选项卡的选项卡视图。在其中一个选项卡中有一个按钮,单击该按钮将打开一个新活动。直到现在一切正常。但是当我从该活动中单击返回按钮时,它会打开其父活动的 onBackPressed 方法.我想打开它自己的 onBackPressed 方法。提前谢谢..
此父活动正在从 tabview 打开
家长活动
public class ProgressActivity extends ActivityGroup
{
private ArrayList<View> history;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.progress_tabview);
this.history = new ArrayList<View>();
}
public void showProgress(View v)
{
Intent intMyProg = new Intent(this,ShowProgress.class);
//startActivity(intMyProg);
View MyView = getLocalActivityManager()
.startActivity("MyIntent", intMyProg
.addFlags(Intent.EXTRA_DOCK_STATE_DESK))
.getDecorView();
replaceView(MyView);
}
public void replaceView(View v)
{
history.add(v);
setContentView(v);
}
//@Override
public void onBackPressed()
{
Toast.makeText(getApplicationContext(), "Back button pressed from parent activity", Toast.LENGTH_SHORT).show();
}
}
儿童活动
public class ShowProgress extends ActivityGroup
{
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.progress);
AlertDialog alertDialog = new AlertDialog.Builder(ShowProgress.this.getParent()).create();
alertDialog.setTitle("Hello ...");
alertDialog.setMessage("Hello world this is Anirban !");
alertDialog.setIcon(R.drawable.tick);
alertDialog.setButton("OK", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int which)
{
Toast.makeText(getApplicationContext(), "You clicked on OK", Toast.LENGTH_SHORT).show();
}
});
alertDialog.show();
}
//@Override
public void onBackPressed()
{
Toast.makeText(getApplicationContext(), "Back button pressed from child activity", Toast.LENGTH_SHORT).show();
}
}
帮助将不胜感激