今天使用activity group的時候,
要在裡面加dialog alert,居然報錯,
我是用tab group -> 透過 activity group -> 載顯示的activity
在顯示的activity下dialog的語法發現以下error:
04-15 15:04:25.027: E/AndroidRuntime(31825): android.view.WindowManager$BadTokenException: Unable to add window -- token android.app.LocalActivityManager$LocalActivityRecord@40d861c0 is not valid; is your activity running?
查了網路後,
可以參考以下兩篇的作法
http://blog.csdn.net/biangren/article/details/7514722
http://blog.csdn.net/hillpool/article/details/7560600
實際作法, 加上 getParent() 即可:
Builder b = new Builder(YourActivity.this.getParent());
b.setTitle("alertTitle");
b.setMessage("AlertMessage");
b.setPositiveButton("positive", new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which)
{
}
});
b.show();
沒有留言:
張貼留言