gpt4 book ai didi

android - 如何通过在android中的警告框外单击来限制用户?

转载 作者:太空狗 更新时间:2023-10-29 15:33:57 24 4
gpt4 key购买 nike

我有一个自定义警报 View ,它会在单击按钮事件时弹出。一切正常。但问题是:如果用户单击警报对话框外部,它就会消失。我想限制用户单击外部。我让他选择取消/交叉按钮来关闭警报对话框。那么如何限制用户在警告框外点击呢?代码:

onCreate 中的代码,用于单击我调用显示对话框的按钮:

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;
}

有什么建议吗?谢谢!

最佳答案

有关此行为的方法有两种:setCancelable()setCanceledOnTouchOutside(),如您在 reference 中所见.

关于android - 如何通过在android中的警告框外单击来限制用户?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7766259/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com