如何通过点击Android的警告框外面来限制用户? [英] how to restrict user by clicking outside the alert box in android?

查看:169
本文介绍了如何通过点击Android的警告框外面来限制用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有它的按钮弹出窗口点击event.all的事情会fine.but的问题是一个自定义的警报视图:
如果用户点击外警告对话框它disappear.i要限制用户的点击进行side.I我给他取消/交叉按钮选择关闭警告对话框。
所以如何限制警告框外的用户点击?
code:

i am having an custom alert view which pop ups on a button click event.all the things are going fine.but the problem is: if user clicks outside alert dialog it disappear.i want to restrict user for clicking out side.I am giving him the choice of cancel/cross button to close alert dialog. so how to restrict user clicking outside the alert box? code:

在的onCreate的code为按钮单击我打电话显示的对话框:

the code in onCreate for button click where i am calling show dialog:

final Button cdButton = (Button) findViewById(R.id.denonCdImage);
    cdButton.setOnClickListener(new Button.OnClickListener(){   
        public void onClick(View v) 
        {
            showDialog(CD_CATG_ID);
        }
    });



protected Dialog onCreateDialog(int id) {   

    AlertDialog.Builder builder;   
    Context mContext = this;   
    LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);   
    View layout = inflater.inflate(R.layout.categorydialog,(ViewGroup) findViewById(R.id.layout_root));   
    GridView gridview = (GridView)layout.findViewById(R.id.gridview);   
    gridview.setAdapter(new ImageAdapter(this)); 
    /** Check the id for the device type for image tobe change */
    switch(id) {   
    case 1 :   // for the cd image 
        gridview.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view,final int position, long id) {   
                Toast.makeText(view.getContext(), "Image selected for CD", 3000).show();
                cdImageId = getImageId(position);
                int elementId = getApplicationContext().getResources().getIdentifier(cdImageId, "drawable", getPackageName());
                cdImageView.setImageResource(elementId);

                Log.d("CdImageid", ""+cdImageId);
                closeDialog(view);
            }   
        });
        builder = new AlertDialog.Builder(mContext);   
        builder.setView(layout);   
        dialog = builder.create();   
        break;  
default:   
        dialog = null;   
    }

    /** onclick listner for the close button */
    ImageView close = (ImageView) layout.findViewById(R.id.close);
    close.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v){
            dialog.dismiss();
        }
    });

    return dialog;   
}  

有什么建议?
谢谢!

any suggestions? thanks!

推荐答案

有两个关于此问题的方法: setCancelable() setCanceledOnTouchOutside( ),你可以在看<一个href=\"http://developer.android.com/reference/android/app/Dialog.html#setCancelable%28boolean%29\">reference.

There are two methods concerning this behaviour: setCancelable() and setCanceledOnTouchOutside() as you can see in the reference.

这篇关于如何通过点击Android的警告框外面来限制用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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