问题描述
我有一点奇怪的问题。当活动开始,我将展示一个对话框说,一些项目正在装载这样的:
对话对话框;@覆盖
公共无效的onCreate(捆绑savedInstanceState)
{
super.onCreate(savedInstanceState);
的setContentView(R.layout.topic_edit); 对话框=新的对话框(本); dialog.setContentView(R.layout.please_wait);
dialog.setTitle(加载评论); TextView的文本=(TextView的)dialog.findViewById(R.id.please_wait_text);
text.setText(请稍候,评论加载...);
dialog.show();
我声明类声明之前对话的对话权,然后每当我尝试用来关闭它dialog.dismiss();
不会关闭
下面是please_wait.xml
<?XML版本=1.0编码=UTF-8&GT?;
<的RelativeLayout的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT><的TextView
机器人:ID =@ + ID / please_wait_text
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT/>
< / RelativeLayout的>
会有人知道为什么对话框不会关闭在 dialog.dismiss()
...我尝试在调用返回后,一个异步调用的解雇。但我没有检查,并执行行 dialog.dismiss()
,只是出于某种原因不关闭对话框。
这是我尝试关闭该对话框:
@覆盖
保护无效onPostExecute(字符串结果)
{
dialog.dismiss();
}
请确保当你执行dialog.dismiss,它是指向你所创建的对话框。你有对话作为一个类变量,有一个高的机会,它被解雇的到来时分配另一个对话框。我有这一个,原来该对话框中的变量在解雇时不再指着我居然对话框。
把一个破发点,看是否在创建/执行对话框变量还是一样可能会帮助
I have a bit of a strange problem. When an activity starts, I show a dialog saying that some items are loading like this:
Dialog dialog;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.topic_edit);
dialog = new Dialog (this);
dialog.setContentView(R.layout.please_wait);
dialog.setTitle("Loading The Comment.");
TextView text = (TextView) dialog.findViewById(R.id.please_wait_text);
text.setText("Please wait while the comment loads...");
dialog.show();
I declare Dialog dialog right before the class declaration, and then whenever I try to dismiss it with dialog.dismiss();
it doesn't close.
Here is the please_wait.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="@+id/please_wait_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
Would someone know why the dialog does not close on dialog.dismiss()
... I try the dismiss in an async call after the call returns. But I did check, and the line dialog.dismiss()
is executed, just for some reason does not close the dialog.
This is how I try to dismiss the dialog:
@Override
protected void onPostExecute(String result)
{
dialog.dismiss();
}
Make sure that when you are executing dialog.dismiss that it is pointing to the dialog you created. You have dialog as a class variable and there is a high chance it was assigned another dialog by the time of dismissal come. I had this one and turned out that dialog variable at dismiss time was no longer pointing to my actually dialog.
Putting a break point and seeing if the dialog variable upon creation/execution is still the same will probably help
这篇关于Android的 - 为什么不对话框关闭后dialog.dismiss()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!