zoukankan      html  css  js  c++  java
  • 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;
    i
    mport 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));
        }

    }
  • 相关阅读:
    多线程 之 NSOperation
    用图像列表播放动画
    视图的动画技术
    自定义软键盘
    UITableView_取消UITableViewCell选择的样式
    UIScrollView 用法
    判断程序运行的设备类型IPad
    修改屏幕的旋转方向,使用与IPHONE以及IPad
    体验Windows XP系统中的网络视频会议
    Sidekiq in Rails
  • 原文地址:https://www.cnblogs.com/wanyakun/p/1883902.html
Copyright © 2011-2022 走看看