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

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id
    ="@+id/ok"
        android:layout_width
    ="fill_parent"
        android:layout_height
    ="fill_parent" >

        <RadioGroup
            
    android:id="@+id/radioGroup1"
            android:layout_width
    ="wrap_content"
            android:layout_height
    ="wrap_content" >
        </RadioGroup>

        <RadioGroup
            
    android:id="@+id/radioGroup2"
            android:layout_width
    ="wrap_content"
            android:layout_height
    ="wrap_content" >
        </RadioGroup>


        <ProgressBar
            
    android:id="@+id/progressBar1"
            style
    ="?android:attr/progressBarStyleLarge"
            android:layout_width
    ="fill_parent"
            android:layout_height
    ="316dp" />

    </LinearLayout>

    //以上是自定义的layout 视图资源文件 ok.xml

    //下面是源文件

    package one.one;


    import android.app.Activity;
    import android.app.AlertDialog;
    import android.os.Bundle;
    import android.view.*;
    import android.app.Dialog;
    import android.content.DialogInterface;
    import android.widget.Button;



    public class WebcyzActivity extends Activity {
        
           private Button b;

        
        
        
        //Activuty父类继承的成员方法,用于创建初始化对话框
        protected Dialog onCreateDialog(int id){
            Dialog dialog; //声明一个对话框对象
            AlertDialog.Builder b = new AlertDialog.Builder(this); //声明一个Alert对话框的建造者 ,this是WebcyzActivity类的实例 ,表示该对话框的背景。
            b.setTitle("标题");//建造过程中的其中一项 :设置标题
            b.setMessage("内容");//建造显示内容
            LayoutInflater inflater = getLayoutInflater();//获取布局泵
            View layout = inflater.inflate(R.layout.ok,(ViewGroup)findViewById(R.id.ok));
            //通过布局泵来构造视图,其中需要的参数有:资源ID和ROOT视图组
            
            b.setView(layout);//设置对话框为视图对象
            b.setPositiveButton("关闭程序", new DialogInterface.OnClickListener() {
                
                public void onClick(DialogInterface dialog, int which) {
                    
                    WebcyzActivity.this.finish(); //关闭外部类对象
                    
                }
            });//建造按钮名称和监听
            dialog = b.create();//创建对话框对象
            
            return dialog;//从活动继承下来的onCreateDialog成员方法中作出返回值,返回的是一个对话框dialog对象。
        }
        
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            
            final String string = "123";
            

            //showDialog(0);//触发对话框,使其显示。
            android.view.View.OnClickListener temp = new View.OnClickListener() {
                
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    System.out.println(string);
                    WebcyzActivity.this.finish();
                }
            };

            b=(Button)findViewById(R.id.button1);
            b.setOnClickListener(temp);
                   
           

        }
    }
  • 相关阅读:
    Java 7如何操纵文件属性
    MS Server中varchar与nvarchar的区别
    【Unity3D】【NGUI】UICamera
    2007LA 3902 网络(树+贪心)
    读取图片的几种方式
    AssetsLibrary 实现访问相册,选取多张照片显示
    UIImagePickerController的用法
    画板的实现
    最近的状态
    富文本的使用-----实现图文混排 文字的检索 (正则表达式)
  • 原文地址:https://www.cnblogs.com/webcyz/p/2529336.html
Copyright © 2011-2022 走看看