来自子节点的onBackPressed总是调用父onBackPressed

时间:2013-03-14 03:18:36

标签: android android-tabhost activitygroup android-tabactivity

我有一个tabview,它有5个tabs.In其中一个标签有一个按钮,点击该按钮,它将打开一个新的活动。现在每件事情都运行正常。但是当我点击该活动的后退按钮时,它打开它的父母activity的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();
    }

 }

帮助将不胜感激

0 个答案:

没有答案