zoukankan      html  css  js  c++  java
  • 对话框

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

    真真是乱死我了!

  • 相关阅读:
    当Django模型迁移时,报No migrations to apply 问题时
    django--各个文件的含义
    django--创建项目
    1013. Battle Over Cities (25)
    1011. World Cup Betting (20)
    1009. Product of Polynomials (25)
    1007. Maximum Subsequence Sum (25)
    1006. Sign In and Sign Out (25)
    1008. Elevator (20)
    1004. Counting Leaves (30)
  • 原文地址:https://www.cnblogs.com/wjhx/p/1680108.html
Copyright © 2011-2022 走看看