如何removeDialog(INT dialogID)的Andr​​oid? [英] How to removeDialog(int dialogID) Android?

查看:133
本文介绍了如何removeDialog(INT dialogID)的Andr​​oid?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经延长我的课,在我所设定的内容视图和其他按钮的ActionListener等的对话......正在发生的事情是,当我创建对话框就说明背景正确。

但再次打开它,并再次被装箱与内容视图的问题,事情随意添加和大部分的UI元素都重复和背景图像消失。

我知道对话框创建一次,并用作缓存,我不希望我知道有在Android中活动removeDialog的方法(INT dialogID),但我不知道是谁用这个,我不'T提供任何ID来我对话,我不知道怎么给ID为对话框。

  #dialog code公共类OptionsDailog扩展对话框实现OnClickListener {
        公共OptionsDailog(活动pContext){
        超(pContext,android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
        mContext = pContext;
        的setContentView(R.layout.option_menu);
        setBasicContents();
    }#options_menu.xml
< XML版本=1.0编码=UTF-8&GT?;
<的RelativeLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT机器人:ID =@ + ID / rl_root_option_menu>
    < RelativeLayout的机器人:layout_height =FILL_PARENT的android:layout_width =FILL_PARENT机器人:背景=@绘制/ bg_episode机器人:ID =@ + ID / rl_option_screen>
        <的LinearLayout机器人:ID =@ + ID / ll_options机器人:方向=垂直的android:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT机器人:layout_centerInParent =真正的>
            <按钮的android:文本=成就机器人:TEXTSIZE =18sp机器人:ID =@ + ID / btn_achievements机器人:背景=@绘制/ bg_options_menu机器人:文字颜色=#FFFFFF的android:layout_width = 250dp机器人:layout_height =60dp>< /按钮>
            <按钮的android:文本=教程机器人:TEXTSIZE =18sp机器人:ID =@ + ID / btn_tutorial机​​器人:背景=@绘制/ bg_options_menu机器人:文字颜色=#FFFFFF的android:layout_width = 250dp机器人:layout_height =60dp>< /按钮>
            <按钮的android:文本=排行榜机器人:TEXTSIZE =18sp机器人:ID =@ + ID / btn_leaderboard机器人:背景=@绘制/ bg_options_menu机器人:文字颜色=#FFFFFF的android:layout_width = 250dp机器人:layout_height =60dp>< /按钮>
            <按钮机器人:ID =@ + ID / btn_music机器人:文本=音乐机器人:TEXTSIZE =18sp机器人:背景=@绘制/ bg_options_menu机器人:文字颜色=#FFFFFF的android:layout_width = 250dp机器人:layout_height =60dp>< /按钮>
            <按钮机器人:ID =@ + ID / btn_sound机器人:TEXTSIZE =18sp机器人:文本=声音机器人:layout_marginBottom =10dip机器人:背景=@绘制/ bg_options_menu机器人:文字颜色= #FFFFFF的android:layout_width =250dp机器人:layout_height =60dp>< /按钮>
        < / LinearLayout中>
    < / RelativeLayout的>
    < ImageButton的机器人:背景=@绘制/ btn_back机器人:layout_alignParentBottom =真正的机器人:layout_alignParentRight =真正的机器人:layout_marginRight =10dp的android:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT机器人: ID =@ + ID / ib_back_options_menu>< / ImageButton的>
< / RelativeLayout的>#Dialog显示code
最后OptionsDailog mDailog =新OptionsDailog(JungleCrashLand.this);
            mDailog.show();


解决方案

对话框类的作品有自己的一套标识符。如果创建createDialog(INT x)的一个对话框,你可以通过这个x作为自己的标识。除去对话框遵循相同的结构:removeDialog(INT x),其中x是,再次,您的对话类型的标识符。是做这样能够不同的对话框的类型,通过自己所定义区分,而不需要延长对话框类

所以基本上是:

 静态最终诠释OPTIONS_DIALOG = 0;
[...]
createDialog(OPTIONS_DIALOG);
[...]
removeDialog(OPTIONS_DIALOG);

,你可以为每个活动只有一个对话,这将删除仅此对话框中,每一个(!)引用。阅读 http://developer.android.com/guide/topics/ui/dialogs。 HTML 充分了解是什么在这里发生了。

I have extended my class with a dialog in which I have set content view and other button actionlisteners etc... what is happening is that when I create my dialog it shows background properly.

but opening it again and again is crating problems with content view, things are added haphazardly and most of the UI elements are repeating and background image is disappeared.

I know that dialog is created once and is used as a cache, I don't want that I know there is a method in Android Activity removeDialog(int dialogID) but I don't know who to use this, I don't give any id to my dialog I don't know how to give id to dialog.

#dialog code

public class OptionsDailog extends Dialog implements OnClickListener {
        public OptionsDailog(Activity pContext) {
        super(pContext, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
        mContext = pContext;
        setContentView(R.layout.option_menu);
        setBasicContents();
    }

#options_menu.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" android:id="@+id/rl_root_option_menu">
    <RelativeLayout android:layout_height="fill_parent" android:layout_width="fill_parent" android:background="@drawable/bg_episode" android:id="@+id/rl_option_screen">
        <LinearLayout android:id="@+id/ll_options" android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true">
            <Button android:text="Achievements" android:textSize="18sp" android:id="@+id/btn_achievements" android:background="@drawable/bg_options_menu" android:textColor="#FFFFFF" android:layout_width="250dp" android:layout_height="60dp"></Button>
            <Button android:text="Tutorial" android:textSize="18sp" android:id="@+id/btn_tutorial" android:background="@drawable/bg_options_menu" android:textColor="#FFFFFF" android:layout_width="250dp" android:layout_height="60dp"></Button>
            <Button android:text="Leaderboard" android:textSize="18sp" android:id="@+id/btn_leaderboard" android:background="@drawable/bg_options_menu" android:textColor="#FFFFFF" android:layout_width="250dp" android:layout_height="60dp"></Button>
            <Button android:id="@+id/btn_music" android:text="Music" android:textSize="18sp" android:background="@drawable/bg_options_menu" android:textColor="#FFFFFF" android:layout_width="250dp" android:layout_height="60dp"></Button>
            <Button android:id="@+id/btn_sound" android:textSize="18sp" android:text="Sound" android:layout_marginBottom="10dip" android:background="@drawable/bg_options_menu" android:textColor="#FFFFFF" android:layout_width="250dp" android:layout_height="60dp"></Button>
        </LinearLayout>
    </RelativeLayout>
    <ImageButton android:background="@drawable/btn_back" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:layout_marginRight="10dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/ib_back_options_menu"></ImageButton>
</RelativeLayout>

#Dialog showing code
final OptionsDailog mDailog = new OptionsDailog(JungleCrashLand.this);
            mDailog.show();

解决方案

The Dialog class works with its own set of identifiers. If you create a dialog with createDialog(int x) you can pass this x as your own identifier. removing the dialog follows the same structure: removeDialog(int x) where x is, again, the identifier of your dialog type. It is done this way to be able to distinguish between different "types" of dialogs, defined by your own, without the need to extend the dialog class.

so basically:

static final int OPTIONS_DIALOG = 0;
[...]
createDialog(OPTIONS_DIALOG);
[...]
removeDialog(OPTIONS_DIALOG);

as you can have only one dialog per activity, this will remove only this dialog and every(!) reference to it. Read http://developer.android.com/guide/topics/ui/dialogs.html to fully understand what is going on here.

这篇关于如何removeDialog(INT dialogID)的Andr​​oid?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆