50个Android开发技巧(09 避免用EditText对日期进行验证)
(原文地址:http://blog.csdn.net/vector_yi/article/details/24424713)
<Button android:id="@+id/details_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:background="@android:drawable/edit_text" /><!--将Button的背景改为EditText的背景-->
package com.manning.androidhacks.hack009; import java.util.Calendar; import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.DatePickerDialog.OnDateSetListener;
import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.DatePicker; public class MainActivity extends Activity { private static final int DATE_DIALOG_ID = 0; private int mYear;
private int mMonth;
private int mDay;
private OnDateSetListener mDateSetListener;
private Button mDateButton; @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main); // get the current date
final Calendar c = Calendar.getInstance();
mYear = c.get(Calendar.YEAR);
mMonth = c.get(Calendar.MONTH);
mDay = c.get(Calendar.DAY_OF_MONTH); mDateSetListener = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
mDateButton.setText(getString(R.string.picked_date_format,
monthOfYear + 1, dayOfMonth, year));
}
}; mDateButton = (Button) findViewById(R.id.details_date);
mDateButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
showDialog(DATE_DIALOG_ID);
}
});
} @Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case DATE_DIALOG_ID:
return new DatePickerDialog(this, mDateSetListener, mYear,
mMonth - 1, mDay);
}
return super.onCreateDialog(id);
} }
50个Android开发技巧(09 避免用EditText对日期进行验证)的更多相关文章
- 50个android开发技巧
50个android开发技巧 http://blog.csdn.net/column/details/androidhacks.html
- 50一个Android开发技巧(01 利用好layout_weight属性)
问题:如何将一个Button放置在布局的中间,并设置其宽度parent的50%? 分析:问题想要达到的效果应该是这样: (原文地址:http://blog.csdn.net/vector_yi/art ...
- 50个Android开发技巧(02 延迟载入和避免反复渲染视图)
当你在Application中创建复杂的布局时.页面的渲染过程也变得更加缓慢. 此时,我们须要利用 <include />标签(避免反复渲染)和 ViewStub类(延迟载入)来优化我们的 ...
- 50个Android开发技巧(24 处理ListView数据为空的情况)
在移动平台上为用户展示数据的一个经常用法是将数据填充进一个List内,而此时须要注意的一点就是: 原文地址:(http://blog.csdn.net/vector_yi/article/d ...
- 50个Android开发技巧(11 为文字加入特效)
问题:怎样构建一个模拟LED数字时钟的页面?效果例如以下图所看到的: (原文地址:http://blog.csdn.net/vector_yi/article/details/24460227) 分析 ...
- 50个Android开发技巧(03 自己定义ViewGroup)
问题:怎样创建一个例如以下图所看到的的布局? 图1 (原文地址:http://blog.csdn.net/vector_yi/article/details/244155 ...
- 50个Android开发技巧(12 为控件加入圆角边框)
控件的圆角边框能够使你的App看起来更美观,事实上实现起来也非常easy. (原文地址:http://blog.csdn.net/vector_yi/article/details/24463025) ...
- 50个Android开发技巧(10 为TextView加入样式)
首先来看一个控件的例子: (原文地址:http://blog.csdn.net/vector_yi/article/details/24428085) 手机上类似这种场景你一定已经见过非常多次了,但有 ...
- 50个Android开发人员必备UI效果源码[转载]
50个Android开发人员必备UI效果源码[转载] http://blog.csdn.net/qq1059458376/article/details/8145497 Android 仿微信之主页面 ...
随机推荐
- VUE:列表的过滤与排序
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- js滚动事件实现滚动触底加载
移动端触底加载时前端开发过程中常用功能,主要是通过三个值的大小来进行判断: 首先介绍jquery的写法,代码如下: $(window).scroll(function(){ var windowH=$ ...
- JAVA集合类型(二)
JAVA集合类型 (现代的变量集群) watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0J ...
- Linux网络编程(附1)——封装read、write
原打算实践简单的模型的时候,主要专注于基本的模型,先用UNIX I/O糊弄下,可是未封装的read和write用起来实在心累,还是直接用前辈们已经实现好的高级版本号read.write. UNIX I ...
- moveToThread的根本目的还是为了处理QObject的事件循环(如果为空指针的话,当前对象的所有的事件都不处理了),看官方说明就知道了
Changes the thread affinity for this object and its children. The object cannot be moved if it has a ...
- tf.placeholder类似函数中的形参
tf.placeholder(dtype, shape=None, name=None) 此函数可以理解为形参,用于定义过程,在执行的时候再赋具体的值 参数: dtype:数据类型.常用的是tf.fl ...
- xBIM 高级01 IFC多模型合并
系列目录 [已更新最新开发文章,点击查看详细] 多模型合并可以实现以下功能: 覆盖多个模型以表现得像一个模型 统一访问数据,就像它是单个模型一样 只读.要修改模型的内容,您必须使用特定模型 不 ...
- spring boot多数据源配置示例
1. application.properties #\u4E3B\u5E93\u914D\u7F6E spring.datasource.primary.url=jdbc:mysql://mysql ...
- 基于Asp.Net webApi owin oauth2的实现
干货地址:https://git.oschina.net/DpMa_/WebApi-Owin-oauth2
- Oracle数据库to_date函数注意事项
使用PL/SQL连接到Oracle数据库服务器,执行一条update语句: update pjnl set transtime = to_date('2015-05-14 12:13:20','yyy ...