瘋狂

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

          android學(xué)習(xí)(各種提示框)

          Posted on 2009-11-04 17:17 瘋狂 閱讀(7302) 評(píng)論(0)  編輯  收藏 所屬分類(lèi): 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"這是一個(gè)提示", Toast.LENGTH_SHORT).show();
              }


              
          public void showAlertDialog() {
                  
          new AlertDialog.Builder(TiShi.this).setTitle("標(biāo)題")
                          .setMessage(
          "提示內(nèi)容").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));
              }

          }
          主站蜘蛛池模板: 乌兰察布市| 辉南县| 乐山市| 寿光市| 成武县| 乐至县| 正蓝旗| 且末县| 称多县| 建平县| 栾川县| 长武县| 社旗县| 桃园县| 阿城市| 江口县| 丘北县| 休宁县| 大埔县| 平昌县| 张家港市| 栾城县| 安庆市| 翁源县| 汨罗市| 长宁县| 库尔勒市| 麻江县| 浏阳市| 石嘴山市| 汶上县| 唐河县| 和顺县| 宁波市| 惠安县| 龙泉市| 澎湖县| 钟山县| 天水市| 驻马店市| 刚察县|