CalendarView cv =(CalendarView)findViewById(RidcalendarView1);
cvsetOnDateChangeListener(new OnDateChangeListener() {
publicvoid onSelectedDayChange(CalendarView view, int year, int month,int dayOfMonth) {
ToastmakeText(MainActivitythis, "onSelectedDayChange", ToastLENGTH_LONG)show();
}
});
安卓里面的时间控件与日期控件都是分开的,如果要同时使用的话用户体验度那肯定不好,整合了安卓中的时间与日期控件,可以同时显示出来方便用户进行选择,使用时只需要将文件导入项目中,再需要用到的地方使用如下代码
[html] view plaincopyprint
package comandyideacalenderdemo;
import javautilCalendar;
import androidappActivity;
import androidappDatePickerDialog;
import androidappDialog;
import androidappTimePickerDialog;
import androidosBundle;
import androidosHandler;
import androidosMessage;
import androidviewView;
import androidwidgetButton;
import androidwidgetDatePicker;
import androidwidgetEditText;
import androidwidgetTimePicker;
public class MainActivity extends Activity {
private EditText showDate = null;
private Button pickDate = null;
private EditText showTime = null;
private Button pickTime = null;
private static final int SHOW_DATAPICK = 0;
private static final int DATE_DIALOG_ID = 1;
private static final int SHOW_TIMEPICK = 2;
private static final int TIME_DIALOG_ID = 3;
private int mYear;
private int mMonth;
private int mDay;
private int mHour;
private int mMinute;
/ Called when the activity is first created /
@Override
public void onCreate(Bundle savedInstanceState) {
superonCreate(savedInstanceState);
setContentView(Rlayoutmain);
initializeViews();
final Calendar c = CalendargetInstance();
mYear = cget(CalendarYEAR);
mMonth = cget(CalendarMONTH);
mDay = cget(CalendarDAY_OF_MONTH);
mHour = cget(CalendarHOUR_OF_DAY);
mMinute = cget(CalendarMINUTE);
setDateTime();
setTimeOfDay();
}
/
初始化控件和UI视图
/
private void initializeViews(){
showDate = (EditText) findViewById(Ridshowdate);
pickDate = (Button) findViewById(Ridpickdate);
showTime = (EditText)findViewById(Ridshowtime);
pickTime = (Button)findViewById(Ridpicktime);
pickDatesetOnClickListener(new ViewOnClickListener() {
@Override
public void onClick(View v) {
Message msg = new Message();
if (pickDateequals((Button) v)) {
msgwhat = MainActivitySHOW_DATAPICK;
}
MainActivitythisdateandtimeHandlersendMessage(msg);
}
});
pickTimesetOnClickListener(new ViewOnClickListener() {
@Override
public void onClick(View v) {
Message msg = new Message();
if (pickTimeequals((Button) v)) {
msgwhat = MainActivitySHOW_TIMEPICK;
}
MainActivitythisdateandtimeHandlersendMessage(msg);
}
});
}
/
设置日期
/
private void setDateTime(){
final Calendar c = CalendargetInstance();
mYear = cget(CalendarYEAR);
mMonth = cget(CalendarMONTH);
mDay = cget(CalendarDAY_OF_MONTH);
updateDateDisplay();
}
/
更新日期显示
/
private void updateDateDisplay(){
showDatesetText(new StringBuilder()append(mYear)append("-")
append((mMonth + 1) < 10 "0" + (mMonth + 1) : (mMonth + 1))append("-")
append((mDay < 10) "0" + mDay : mDay));
}
/
日期控件的事件
/
private DatePickerDialogOnDateSetListener mDateSetListener = new DatePickerDialogOnDateSetListener() {
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
mYear = year;
mMonth = monthOfYear;
mDay = dayOfMonth;
updateDateDisplay();
}
};
/
设置时间
/
private void setTimeOfDay(){
final Calendar c = CalendargetInstance();
mHour = cget(CalendarHOUR_OF_DAY);
mMinute = cget(CalendarMINUTE);
updateTimeDisplay();
}
/
更新时间显示
/
private void updateTimeDisplay(){
showTimesetText(new StringBuilder()append(mHour)append(":")
append((mMinute < 10) "0" + mMinute : mMinute));
}
/
时间控件事件
/
private TimePickerDialogOnTimeSetListener mTimeSetListener = new TimePickerDialogOnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
mHour = hourOfDay;
mMinute = minute;
updateTimeDisplay();
}
};
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case DATE_DIALOG_ID:
return new DatePickerDialog(this, mDateSetListener, mYear, mMonth,
mDay);
case TIME_DIALOG_ID:
return new TimePickerDialog(this, mTimeSetListener, mHour, mMinute, true);
}
return null;
}
@Override
protected void onPrepareDialog(int id, Dialog dialog) {
switch (id) {
case DATE_DIALOG_ID:
((DatePickerDialog) dialog)updateDate(mYear, mMonth, mDay);
break;
case TIME_DIALOG_ID:
((TimePickerDialog) dialog)updateTime(mHour, mMinute);
break;
}
}
/
处理日期和时间控件的Handler
/
Handler dateandtimeHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msgwhat) {
case MainActivitySHOW_DATAPICK:
showDialog(DATE_DIALOG_ID);
break;
case MainActivitySHOW_TIMEPICK:
showDialog(TIME_DIALOG_ID);
break;
}
}
};
}
Android开发有没有人做过日历控件,可以签到的
可以按照这个思路:
首先是MainActivity,源码如下
<pre name=code class="java">public class MainActivity extends Activity { private SignCalendar calendar; private String date; private int years; private String months; private Button btn_sign; @Override protected void onCreate(Bundle savedInstanceState) { superonCreate(savedInstanceState); setContentView(Rlayoutactivity_main); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); Date curDate = new Date(SystemcurrentTimeMillis()); 获取当前时间 date = formatterformat(curDate); calendar = (SignCalendar) findViewById(Ridsc_main); btn_sign = (Button) findViewById(Ridbtn_sign); btn_signsetOnClickListener(new OnClickListener() { @Override public void onClick(View v) { TODO Auto-generated method stub List<String> list = new ArrayList<String>(); listadd("2016-06-30"); listadd(date); calendarsetCalendarDaysBgColor(list, Rdrawablebg_sign_today); calendaraddMarks(list, 0); } }); } }以下是布局文件:
<LinearLayout xmlns:android=":schemasandroid/apk/res/android" xmlns:tools=":schemasandroid/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="hchengsigncalendarMainActivity" > <hchengsigncalendarSignCalendar android:id="@+id/sc_main" android:layout_width="match_parent" android:layout_height="320dp" android:clickable="true" > </hchengsigncalendarSignCalendar> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="15dp" android:orientation="horizontal" > <Button android:id="@+id/btn_sign" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="15dp" android:layout_marginRight="15dp" android:background="#f00" android:text="签到" android:textColor="#fff" /> </LinearLayout> </LinearLayout>有没有人用过bootstrap中datepicker日历控件
首先,不管是datepicker还是datetimepicker,都是bootstrap爱好者编写的,并不是itter官方提供的。
你想设置默认时间,其实使用value属性就可以了,这与datetimepicker无关,只是input本身的属性:
<input type=text value="26/08/2013 19:14:58" data-format="dd/MM/yyyy hh:mm:ss" id="dp2">
$('#dp2')datetimepicker ();
以上会使默认时间设置为26/08/2013 19:14:58,如果你希望默认时间为当前时间,使用DOM *** 作下input的value属性就可以了。
Android开发中几种有用的的日历控件实现
道客巴巴精品文档 android日历控件 android 控件 android 自定义控件 android 日期控件 android 控件属性 android 控件不可见 android 时间控件 android 浏览器控件 android组合控件 android常用控件
有没有人是做android开发的??有
有没有好的日历控件啊?梅花雨的日历控件,搜搜看咯
幼师有没有人做过?可以吗?你好!看了你的描述,幼师都没有人做过,可以吗?这个问题是,需要本人喜欢不喜欢而决定,现在幼儿园百分之九十是私人办的,幼儿园主要依靠入园人数收入来维持,在幼儿园工作以及待遇,还是不错的,只要幼儿园越办越好,就会吸引更多幼儿入园,所以幼儿园老师将起着重要作用,完全没问题,祝好运!
有没有人做过openmeetings的二次开发啊求帮助文档上说用run as ant build,我运行之后报错
Buildfile: D:\我的文件\视频会议\apache-openmeetings-302-src\buildxml
cleanclasses:
[delete] Deleting directory D:\我的文件\视频会议\apache-openmeetings-302-src\build\classes\openmeetings
cleandist:
clean:
info:
1)你这是若干个项目吧
2)部署的话没文档吗?
3)关于 red5 的应用的部署,我以前整理过,帮你找找看
道客巴巴精品文档 android日历控件 android 控件 android 自定义控件 android 日期控件 android 控件属性 android 控件不可见 android 时间控件 android 浏览器控件 android组合控件 android常用控件
下拉框,要看你设置的是什么类型的对象
AutoCompleteTextViewsetOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<> parent, View view, int position, long id) {
Object obj = parentgetItemAtPosition(position);
//这个就是取点击的条目绑定的值,
//实际上返回的就是适配器的 AdaptergetItem(position);
}
});
请采纳
以上就是关于android怎么把3.0自带日历控件calendarview每个日期按钮设置事件,如跳转之类的。全部的内容,包括:android怎么把3.0自带日历控件calendarview每个日期按钮设置事件,如跳转之类的。、Android开发中能不能把时间控件跟日期控件合在一起、Android开发有没有人做过日历控件,可以签到的等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)