瘋狂

          STANDING ON THE SHOULDERS OF GIANTS
          posts - 481, comments - 486, trackbacks - 0, articles - 1
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          android學習(各種提示框)

          Posted on 2009-11-04 17:17 瘋狂 閱讀(7304) 評論(0)  編輯  收藏 所屬分類: android
               代碼:
            
          package com.tishi;

          import java.util.Calendar;
          import java.util.Date;
          import java.util.Locale;

          import android.app.Activity;
          import android.app.AlertDialog;
          import android.app.DatePickerDialog;
          import android.app.DatePickerDialog.OnDateSetListener;
          import android.content.DialogInterface;
          import android.os.Bundle;
          import android.view.View;
          import android.view.View.OnClickListener;
          import android.widget.Button;
          import android.widget.DatePicker;
          import android.widget.TextView;
          import android.widget.Toast;

          public class TiShi extends Activity implements OnClickListener,
                  OnDateSetListener 
          {
              
          /** Called when the activity is first created. */
              @Override
              
          public void onCreate(Bundle savedInstanceState) {
                  
          super.onCreate(savedInstanceState);
                  setContentView(R.layout.main);
                  
          final Button click1 = (Button) findViewById(R.id.click1);
                  
          final Button click2 = (Button) findViewById(R.id.click2);
                  
          final Button click3 = (Button) findViewById(R.id.click3);
                  click1.setOnClickListener(
          this);
                  click2.setOnClickListener(
          this);
                  click3.setOnClickListener(
          this);
              }


              
          public void onClick(View v) {
                  
          switch (v.getId()) {
                  
          case R.id.click1:
                      showToast();
                      
          break;
                  
          case R.id.click2:
                      showAlertDialog();
                      
          break;
                  
          case R.id.click3:
                      showDatePickerDialog();
                      
          break;
                  
          default:
                      
          break;
                  }


              }


              
          public void showToast() {
                  Toast.makeText(TiShi.
          this"這是一個提示", Toast.LENGTH_SHORT).show();
              }


              
          public void showAlertDialog() {
                  
          new AlertDialog.Builder(TiShi.this).setTitle("標題")
                          .setMessage(
          "提示內容").setPositiveButton("確定",
                                  
          new DialogInterface.OnClickListener() {
                                      
          public void onClick(DialogInterface dialog,
                                              
          int whichButton) {
                                          setResult(RESULT_OK);
          // 確定按鈕事件
                                          finish();
                                      }

                                  }
          )

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

                              
          public void onClick(DialogInterface dialog, int which) {
                                  TextView txt 
          = (TextView) findViewById(R.id.text);
                                  txt.setText(
          "你選擇了取消。");

                              }

                          }
          ).show();
              }


              
          public void showDatePickerDialog() {
                  Calendar d 
          = Calendar.getInstance(Locale.CHINA);
                  d.setTime(
          new Date());
                  
          new DatePickerDialog(thisthis, d.get(Calendar.MONTH), d
                          .get(Calendar.DAY_OF_MONTH), d.get(Calendar.DAY_OF_YEAR))
                          .show();
              }


              
          public void onDateSet(DatePicker view, int year, int monthOfYear,
                      
          int dayOfMonth) {
                  TextView txt 
          = (TextView) findViewById(R.id.text);
                  txt.setText(Integer.toString(year) 
          + "-"
                          
          + Integer.toString(monthOfYear) + "-"
                          
          + Integer.toString(dayOfMonth));
              }

          }
          主站蜘蛛池模板: 榆树市| 宝应县| 元朗区| 皋兰县| 卓尼县| 通许县| 新蔡县| 郸城县| 综艺| 汝阳县| 老河口市| 广水市| 泽库县| 本溪市| 丁青县| 营口市| 天门市| 台东县| 焉耆| 洪雅县| 杭锦旗| 汤原县| 永德县| 双桥区| 赤水市| 铜梁县| 长寿区| 德州市| 芦溪县| 浦江县| 嵊泗县| 曲麻莱县| 阿鲁科尔沁旗| 勃利县| 两当县| 小金县| 康平县| 岑巩县| 丰县| 广南县| 象山县|