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

    }
}

 

posted @ 2012-05-31 23:57  正月龙  阅读(290)  评论(0编辑  收藏  举报
留言板