• 对话框


    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>

    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>

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

    真真是乱死我了!

  • 相关阅读:
    hdu4930 Fighting the Landlords(模拟 多校6)
    hdu4888 多校B 最大流以及最大流唯一推断+输出方案
    xUtils介绍 -- DbUtils、ViewUtils、HttpUtils、BitmapUtils
    java 读取properties文件
    poj1062昂贵的聘礼
    杭电 HDU 2717 Catch That Cow
    iOS使用自己定义字体
    Elasticsearch 2014年10月简报
    html 上下左右都居中
    Linux 比较判断运算(if else)
  • 原文地址:https://www.cnblogs.com/wjhx/p/1680108.html
Copyright © 2020-2023  润新知