我开发一个样本app.I我能够有一些丝毫不差和按钮上显示按钮点击警报。但现在我想告诉有的用户名(标签)文本字段(编辑字段)一个弹出窗口, 和一个按钮。 在点击button.can我再拍弹出xml文件是什么?
公共无效selfDestruct(查看视图){
// Kabloey
Log.d(纳文,测试====);
的System.out.println(---------------------- ghfgjhf -----------------);
AlertDialog alertDialog =新AlertDialog.Builder(SecondActivity.this).create();
alertDialog.setTitle(复位......);
alertDialog.setMessage(Rû确定吗?);
alertDialog.setButton(OK,新DialogInterface.OnClickListener(){
公共无效的onClick(DialogInterface对话,诠释它){
//在这里你可以添加功能
}});
alertDialog.show();
}
 
<按钮
机器人:layout_height =WRAP_CONTENT
机器人:layout_width =WRAP_CONTENT
机器人:文本=@字符串/ self_destruct
机器人:的onClick =selfDestruct/>
解决方案
custom_dialog.xml
< XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:方向=垂直>
<的EditText
机器人:ID =@ + ID / EDITTEXT
机器人:提示=输入一些东西
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT>
<不是requestFocus />
< /的EditText>
<的LinearLayout
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:方向=横向
机器人:layout_marginTop =10dp>
<按钮
机器人:ID =@ + ID /保存
机器人:layout_marginTop =15dp
机器人:layout_weight =1
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:文本=SAVE/>
<按钮
机器人:ID =@ + ID /取消
机器人:layout_marginTop =15dp
机器人:layout_weight =1
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:文本=取消/>
< / LinearLayout中>
< / LinearLayout中>
需要夸大custom_dialog.xml
最后一个对话框对话框=新的对话框(本);
dialog.setContentView(R.layout.custom_dialog);
dialog.setTitle(自定义警告对话框);
最后的EditText EDITTEXT =(EditText上)dialog.findViewById(R.id.editText);
按钮btnSave =(按钮)dialog.findViewById(R.id.save);
按钮btnCancel =(按钮)dialog.findViewById(R.id.cancel);
dialog.show();
I am developing a sample app.I am able to show alert on button click having some tittle and button .But now I want to show a pop up window having username (Label) and text field (Edit field) and a button. on click on button.can I make another popup xml file for that ?
public void selfDestruct(View view) {
// Kabloey
Log.d("Naveen", "Test====");
System.out.println("----------------------ghfgjhf-----------------");
AlertDialog alertDialog = new AlertDialog.Builder(SecondActivity.this).create();
alertDialog.setTitle("Reset...");
alertDialog.setMessage("R u sure?");
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//here you can add functions
} });
alertDialog.show();
}
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/self_destruct"
android:onClick="selfDestruct" />
解决方案
custom_dialog.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<EditText
android:id="@+id/editText"
android:hint="Enter some thing"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<requestFocus />
</EditText>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="10dp">
<Button
android:id="@+id/save"
android:layout_marginTop="15dp"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="SAVE" />
<Button
android:id="@+id/cancel"
android:layout_marginTop="15dp"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Cancel" />
</LinearLayout>
</LinearLayout>
Need to inflate custom_dialog.xml
final Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.custom_dialog);
dialog.setTitle("Custom Alert Dialog");
final EditText editText = (EditText) dialog.findViewById(R.id.editText);
Button btnSave = (Button) dialog.findViewById(R.id.save);
Button btnCancel = (Button) dialog.findViewById(R.id.cancel);
dialog.show();