zoukankan      html  css  js  c++  java
  • Dialog的使用

    看了SDK,写了这几个例子。

    代码如下:

    package com.chaowen;

    import android.app.Activity;
    import android.app.AlertDialog;
    import android.app.Dialog;
    import android.app.ProgressDialog;
    import android.app.AlertDialog.Builder;
    import android.content.Context;
    import android.content.DialogInterface;
    import android.os.Bundle;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.ImageView;
    import android.widget.TextView;
    import android.widget.Toast;

    publicclass DialogActivity extends Activity {
    private Button dialog1,dialog2,dialog3,dialog4,dialog5,dialog6,dialog7;
    @Override
    publicvoid onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    dialog1
    = (Button)findViewById(R.id.button01);
    dialog2
    = (Button)findViewById(R.id.button02);
    dialog3
    = (Button)findViewById(R.id.button03);
    dialog4
    = (Button)findViewById(R.id.button04);
    dialog5
    = (Button)findViewById(R.id.button05);
    dialog6
    = (Button)findViewById(R.id.button06);
    dialog7
    = (Button)findViewById(R.id.button07);


    dialog1.setOnClickListener(
    new OnClickListener() {

    @Override
    publicvoid onClick(View v) {
    AlertDialog.Builder builder
    =new AlertDialog.Builder(DialogActivity.this);
    builder.setMessage(
    "这是一个简单的对话框")
    .setCancelable(
    false)
    .setPositiveButton(
    "确定", new DialogInterface.OnClickListener() {

    @Override
    publicvoid onClick(DialogInterface dialog, int which) {
    Toast.makeText(DialogActivity.
    this, "你按了确定", Toast.LENGTH_LONG).show();

    }
    })
    .setNegativeButton(
    "取消", new DialogInterface.OnClickListener() {

    @Override
    publicvoid onClick(DialogInterface dialog, int which) {
    Toast.makeText(DialogActivity.
    this, "你按了取消", Toast.LENGTH_LONG).show();

    }
    });
    AlertDialog alert
    =builder.create();
    alert.show();
    }
    });


    dialog2.setOnClickListener(
    new OnClickListener() {

    @Override
    publicvoid onClick(View v) {
    final CharSequence[] items = {"Red","Green","Blue"};
    AlertDialog.Builder builder
    =new AlertDialog.Builder(DialogActivity.this);
    builder.setTitle(
    "选择颜色");
    builder.setItems(items,
    new DialogInterface.OnClickListener() {

    @Override
    publicvoid onClick(DialogInterface dialog, int item) {
    Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_LONG).show();

    }
    });
    AlertDialog alert
    = builder.create();
    alert.show();
    }
    });


    dialog3.setOnClickListener(
    new OnClickListener() {

    @Override
    publicvoid onClick(View v) {
    final CharSequence[] items = {"Red","Green","Blue"};
    AlertDialog.Builder builder
    =new AlertDialog.Builder(DialogActivity.this);
    builder.setTitle(
    "选择颜色");
    builder.setSingleChoiceItems(items,
    -1, new DialogInterface.OnClickListener() {

    @Override
    publicvoid onClick(DialogInterface dialog, int item) {
    Toast.makeText(getApplicationContext(), items[item],Toast.LENGTH_LONG).show();

    }
    });

    AlertDialog alert
    = builder.create();
    alert.show();
    }
    });

    dialog4.setOnClickListener(
    new OnClickListener() {

    @Override
    publicvoid onClick(View v) {
    ProgressDialog dialog
    = ProgressDialog.show(DialogActivity.this, "这是一个圆形处理条",
    "Loading. Please wait...", true);

    }
    });


    dialog5.setOnClickListener(
    new OnClickListener() {

    @Override
    publicvoid onClick(View v) {
    ProgressDialog pd
    =new ProgressDialog(DialogActivity.this);
    pd.setTitle(
    "这是一个水平进度条");
    pd.setMessage(
    "Load.....");
    pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    pd.setCancelable(
    true);
    pd.show();
    }
    });


    //自定义处理条一
    dialog6.setOnClickListener(new OnClickListener() {

    @Override
    publicvoid onClick(View v) {
    AlertDialog.Builder builder;
    AlertDialog alertDialog;
    Context mContext
    = DialogActivity.this;
    LayoutInflater inflater
    = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
    View layout
    = inflater.inflate(R.layout.custom_dialog, (ViewGroup)findViewById(R.id.layout_root));


    TextView text
    = (TextView) layout.findViewById(R.id.text);
    text.setText(
    "Hello, this is a custom dialog!");
    ImageView image
    = (ImageView) layout.findViewById(R.id.image);
    image.setImageResource(R.drawable.icon);
    builder
    =new AlertDialog.Builder(mContext);
    builder.setView(layout);
    alertDialog
    = builder.create();
    alertDialog.show();
    }
    });


    //自定义处理条二
    dialog7.setOnClickListener(new OnClickListener() {

    @Override
    publicvoid onClick(View v) {
    Context mContext
    = DialogActivity.this;
    Dialog dialog
    =new Dialog(mContext);

    dialog.setContentView(R.layout.custom_dialog);
    dialog.setTitle(
    "Custom Dialog");

    TextView text
    = (TextView) dialog.findViewById(R.id.text);
    text.setText(
    "Hello, this is a custom dialog!");
    ImageView image
    = (ImageView) dialog.findViewById(R.id.image);
    image.setImageResource(R.drawable.icon);
    dialog.show();
    }
    });
    }


    }

    源码下载:

     

    http://u.115.com/file/aq25dgey

  • 相关阅读:
    在没有备份的情况下重新创建丢失的数据文件 (Doc ID 1149946.1)
    How to recover a skipped tablespace after an incomplete recovery? (Doc ID 1561645.1)
    RMAN DUPLICATE DATABASE with SET NEWNAME failed: RMAN-05501 RMAN-05517 (Doc ID 387093.1)
    Rman Enhancements(增强) In Oracle 11g. (Doc ID 1115423.1)
    Resolving RMAN-06023 or RMAN-06025 (Doc ID 2038119.1)
    Checklist for an RMAN Restore (Doc ID 1554636.1)
    Recover With Until Time fails With RMAN-20207 When Time Is Before Last RESETLOGS (Doc ID 159405.1)
    ODA: After Apply ODA 12.2.1.2.0 Patch, Unable to Create TableSpace Due to [ORA-15001: diskgroup "DATA" does not exist or is not mounted | ORA-15040: diskgroup is incomplete] (Doc ID 2375553.1)
    How to restore and recover a database from an RMAN backup. (Doc ID 881395.1)
    How To Restore Rman Backups On A Different Node When The Directory Structures Are Different (Doc ID 419137.1)
  • 原文地址:https://www.cnblogs.com/andgoo/p/2094986.html
Copyright © 2011-2022 走看看