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

    真真是乱死我了!

  • 相关阅读:
    第八章:简单之美——布尔代数和搜索引擎的索引
    第六章:信息的度量和作用
    第五章:隐马尔可夫模型
    第四章谈谈中文分词
    第二章:自然语言处理———从规则到统计
    转:中文分词算法笔记
    NLTK之WordNet 接口【转】
    sentiwordnet的简单使用
    20169202 2016-2017-2 《移动平台开发实践》实验总结--七周
    20169202 2016-2017-2《移动平台》第七周学习总结
  • 原文地址:https://www.cnblogs.com/wjhx/p/1680108.html
Copyright © 2011-2022 走看看