警告对话框 [英] Alert Dialog Box
本文介绍了警告对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在code一个警告对话框,我想一个值赋给一个变量作为取消按钮是pssed该对话框$ P $。
我的实际code为 -
私人无效点击(){
AlertDialog.Builder建设者=新AlertDialog.Builder(Feedback.this);
builder.setTitle(反馈);
builder.setSingleChoiceItems(选项,-1,
新DialogInterface.OnClickListener(){
公共无效的onClick(DialogInterface对话,诠释它){
// TODO自动生成方法存根
切换(这){
情况下0:
字符串URL =http://killmathsapp.blogspot.in/;
意图I =新的意图(Intent.ACTION_VIEW);
i.setData(Uri.parse(URL));
startActivity(ⅰ);
打破;
情况1:
意图S =新意图(Intent.ACTION_SEND);
s.setType(纯/文);
s.putExtra(android.content.Intent.EXTRA_EMAIL,
新的String [] {pankaj_88_88@yahoo.com});
s.putExtra(android.content.Intent.EXTRA_SUBJECT,
从应用反馈);
startActivity(多个);
打破;
}
}
});
AlertDialog警报= builder.create();
alert.setCancelable(真正的);
alert.show();
}
解决方案
很简单,在对话框中警报消息的方式...
公共无效的onClick(视图v)
{
如果(somthing_wrong)
{
对话D =新的对话框(AmitregistrationActivity.this);
d.setContentView(R.layout.detail);
d.setTitle(警告......);
d.show();
}
其他{
要执行// code
}
}
你也必须创建这样一个detail.xml文件
< ImageView的
机器人:ID =@ + ID / imageView1
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_alignParentLeft =真
机器人:layout_alignParentTop =真
机器人:SRC =@可绘制/详细信息/>
<的TextView
机器人:ID =@ + ID / textView1
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_alignParentTop =真
机器人:layout_marginLeft =26dp
机器人:layout_marginTop =15dp
机器人:layout_toRightOf =@ + ID / imageView1
机器人:文本=请填写所有的细节......机器人:TEXTSIZE =20dp/>
I have a alert dialog box in my code and I want to assign a value to a variable as the cancel button is pressed for that dialog.
My actual code is -
private void clicked() {
AlertDialog.Builder builder = new AlertDialog.Builder(Feedback.this);
builder.setTitle("FEEDBACK");
builder.setSingleChoiceItems(options, -1,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
switch (which) {
case 0:
String url = "http://killmathsapp.blogspot.in/";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
break;
case 1:
Intent s = new Intent(Intent.ACTION_SEND);
s.setType("plain/text");
s.putExtra(android.content.Intent.EXTRA_EMAIL,
new String[] { "pankaj_88_88@yahoo.com" });
s.putExtra(android.content.Intent.EXTRA_SUBJECT,
"feedback from app");
startActivity(s);
break;
}
}
});
AlertDialog alert = builder.create();
alert.setCancelable(true);
alert.show();
}
解决方案
very simple way for alert message in dialog box...
public void onClick(View v)
{
if(somthing_wrong)
{
Dialog d=new Dialog(AmitregistrationActivity.this);
d.setContentView(R.layout.detail);
d.setTitle("Warning....");
d.show();
}
else{
//Code that you want to execute
}
}
also you have to create an detail.xml file like this
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="@drawable/detail" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="26dp"
android:layout_marginTop="15dp"
android:layout_toRightOf="@+id/imageView1"
android:text="Please fill all Details..." android:textSize="20dp"/>
这篇关于警告对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文