对话框
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="计算请点按钮"></TextView>
<Button android:id="@+id/Button01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="计算"></Button>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="计算请点按钮"></TextView>
<Button android:id="@+id/Button01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="计算"></Button>
</LinearLayout>
main2.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout android:id="@+id/LinearLayout01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical">
<TextView android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="第一个值"></TextView>
<EditText android:id="@+id/EditText01" android:layout_width="wrap_content" android:layout_height="wrap_content"></EditText>
<TextView android:id="@+id/TextView02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="第二个值"></TextView>
<EditText android:id="@+id/EditText02" android:layout_width="wrap_content" android:layout_height="wrap_content"></EditText>
</LinearLayout>
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout android:id="@+id/LinearLayout01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical">
<TextView android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="第一个值"></TextView>
<EditText android:id="@+id/EditText01" android:layout_width="wrap_content" android:layout_height="wrap_content"></EditText>
<TextView android:id="@+id/TextView02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="第二个值"></TextView>
<EditText android:id="@+id/EditText02" android:layout_width="wrap_content" android:layout_height="wrap_content"></EditText>
</LinearLayout>
</LinearLayout>
OnCreate
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
t1 = (TextView)findViewById(R.id.TextView01);
Button btn = (Button)findViewById(R.id.Button01);
btn.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v){
Dialog dlg = new AlertDialog.Builder(HelloAndroid.this)
.setTitle("提示")
.setMessage("点击确定,进行计算")
.setPositiveButton("确定", new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dlg, int btn){
LayoutInflater fac = LayoutInflater.from(HelloAndroid.this);
final View dv = fac.inflate(R.layout.main2, null);
_dlg = new AlertDialog.Builder(HelloAndroid.this)
.setTitle("显示")
.setView(dv)
.setPositiveButton("确定", new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int btn){
_dlg1 = ProgressDialog.show(HelloAndroid.this, "请稍等...", "正在计算...");
new Thread(){
public void run(){
try{
sleep(5000);
int i1 = Integer.parseInt(((EditText)_dlg.findViewById(R.id.EditText01)).getText().toString());
int i2 = Integer.parseInt(((EditText)_dlg.findViewById(R.id.EditText02)).getText().toString());
t1.setText(Integer.toString(i1+i2));
}
catch(Exception e){
e.printStackTrace();
}
finally{
_dlg1.dismiss();
}
}
}.start();
}
})
.show();
}
})
.setNeutralButton("关闭", new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int btn){
HelloAndroid.this.finish();
}
})
.show();
}
});
}
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
t1 = (TextView)findViewById(R.id.TextView01);
Button btn = (Button)findViewById(R.id.Button01);
btn.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v){
Dialog dlg = new AlertDialog.Builder(HelloAndroid.this)
.setTitle("提示")
.setMessage("点击确定,进行计算")
.setPositiveButton("确定", new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dlg, int btn){
LayoutInflater fac = LayoutInflater.from(HelloAndroid.this);
final View dv = fac.inflate(R.layout.main2, null);
_dlg = new AlertDialog.Builder(HelloAndroid.this)
.setTitle("显示")
.setView(dv)
.setPositiveButton("确定", new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int btn){
_dlg1 = ProgressDialog.show(HelloAndroid.this, "请稍等...", "正在计算...");
new Thread(){
public void run(){
try{
sleep(5000);
int i1 = Integer.parseInt(((EditText)_dlg.findViewById(R.id.EditText01)).getText().toString());
int i2 = Integer.parseInt(((EditText)_dlg.findViewById(R.id.EditText02)).getText().toString());
t1.setText(Integer.toString(i1+i2));
}
catch(Exception e){
e.printStackTrace();
}
finally{
_dlg1.dismiss();
}
}
}.start();
}
})
.show();
}
})
.setNeutralButton("关闭", new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int btn){
HelloAndroid.this.finish();
}
})
.show();
}
});
}
真真是乱死我了!