当前位置:首页 » 安卓系统 » android时间段选择

android时间段选择

发布时间: 2024-07-02 20:38:54

㈠ (高分,Android)求一个时间选择控件,支持选择一段时间

Android 时间段选择

看看这个符合不

㈡ android 仿预订日历时间选择(如去哪儿,携程

看标题就知道了,一个日历选择,类似于去哪儿,携程,酒店预订功能
调用方法
package com.fly.caldroid;import android.annotation.SuppressLint;import android.app.Activity;import android.content.Intent;import android.content.res.Configuration;import android.os.Bundle;import android.view.View;import com.wz.caldroid.CalendarCellDecorator;import com.wz.caldroid.CalendarPickerView;import java.util.ArrayList;import java.util.Calendar;import java.util.Collections;import java.util.Date;@SuppressLint("SimpleDateFormat")public class CaldroidActivity extends Activity { private CalendarPickerView calendar; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.calendar_activity); Bundle myBundle = getIntent().getExtras(); long seleteTime = myBundle.getLong("selete_time"); final Calendar nextYear = Calendar.getInstance(); nextYear.add(Calendar.MONTH, 3); final Calendar lastYear = Calendar.getInstance(); lastYear.add(Calendar.MONTH, 0); calendar = (CalendarPickerView) findViewById(R.id.calendar_view); Calendar today = Calendar.getInstance(); ArrayList<Date> dates = new ArrayList<Date>(); if (seleteTime>0){
Date d1=new Date(seleteTime); dates.add(d1); }else{
dates.add(today.getTime()); } calendar.setDecorators(Collections.<CalendarCellDecorator>emptyList()); calendar.init(lastYear.getTime(), nextYear.getTime()) // .inMode(CalendarPickerView.SelectionMode.MULTIPLE) // .withSelectedDate(dates.get(0)); initButtonListeners(); } private void initButtonListeners() { calendar.setOnDateSelectedListener(new CalendarPickerView.OnDateSelectedListener() { @Override public void onDateSelected(Date date) {
Intent intent = new Intent(); intent.putExtra("SELETE_DATA_TIME", calendar.getSelectedDate().getTime()); setResult(2, intent); finish(); } @Override public void onDateUnselected(Date date) {

}
}); View titlebar_img_back=findViewById(R.id.titlebar_img_back); titlebar_img_back.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) {
finish(); }
}); } @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); }
}

layout======
calendar_activity

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" > <RelativeLayout android:id="@+id/title_content_layout" android:layout_width="match_parent" android:layout_height="47.5dp" android:background="@color/big_red"> <TextView android:id="@+id/titlebar_text_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:layout_marginLeft="10dp" android:layout_toRightOf="@+id/titlebar_img_back" android:maxEms="8" android:singleLine="true" android:text="选择日历" android:textColor="@color/white" android:textSize="18sp" android:visibility="visible" /> <ImageView android:id="@+id/titlebar_img_back" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:padding="5dp" android:src="@drawable/back_ic" android:visibility="visible" /> </RelativeLayout> <com.wz.caldroid.CalendarPickerView android:id="@+id/calendar_view" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:paddingLeft="16dp" android:paddingRight="16dp" android:paddingBottom="16dp" android:scrollbarStyle="outsideOverlay" android:clipToPadding="false" android:background="#FFFFFF" /></LinearLayout>

在textview上显示时间
package com.fly.caldroid;import android.content.Intent;import android.os.Bundle;import android.support.v7.app.AppCompatActivity;import android.view.View;import android.widget.TextView;import java.text.SimpleDateFormat;import java.util.Date;public class MainActivity extends AppCompatActivity { private long seleteTime = 0; private TextView time_choice_view; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); time_choice_view = (TextView) findViewById(R.id.time_choice_view); time_choice_view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) {
Intent intent = new Intent(); Bundle bundle = new Bundle(); bundle.putLong("selete_time", seleteTime); intent.putExtras(bundle); intent.setClass(MainActivity.this, CaldroidActivity.class); startActivityForResult(intent, 5); }
}); } @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == 5) { if (resultCode == 2) { seleteTime = data.getLongExtra("SELETE_DATA_TIME", 0); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); Date d1 = new Date(seleteTime); String t1 = format.format(d1); if (seleteTime > 0) { time_choice_view.setText(t1); } else { return; }
}
} super.onActivityResult(requestCode, resultCode, data); }
}

㈢ android 怎么判断是否在时间段 范围内

Calendar cal = Calendar.getInstance();// 当前日期
int hour = cal.get(Calendar.HOUR_OF_DAY);// 获取小时
int minute = cal.get(Calendar.MINUTE);// 获取分钟
int minuteOfDay = hour * 60 + minute;// 从0:00分开是到目前为止的分钟数
final int start = 17 * 60 + 20;// 起始时间 17:20的分钟数
final int end = 19 * 60;// 结束时间 19:00的分钟数
if (minuteOfDay >= start && minuteOfDay <= end) {
System.out.println("在外围内");
} else {
System.out.println("在外围外");
}

推荐学安卓的利器:

android学习手册,里面有源码。android学习手册包含9个章节,108个例子,源码文档随便看,例子都是可交互,可运行,源码采用android studio目录结构,高亮显示代码,文档都采用文档结构图显示,可以快速定位。360手机助手中下载,图标上有贝壳:

热点内容
威立信监控原始密码是多少 发布:2024-11-26 09:24:06 浏览:487
超凡先锋选择不了服务器该怎么办 发布:2024-11-26 09:15:56 浏览:336
搭建ff服务器喝茶 发布:2024-11-26 09:10:09 浏览:845
乐山云服务器公司 发布:2024-11-26 08:59:44 浏览:953
ftp工具可以上传吗 发布:2024-11-26 08:55:04 浏览:569
压缩量密封 发布:2024-11-26 08:52:10 浏览:581
java把一个list 发布:2024-11-26 08:38:38 浏览:585
混沌珠算法 发布:2024-11-26 08:29:17 浏览:163
阿里云解析不到服务器 发布:2024-11-26 07:57:59 浏览:493
python矩阵的行数 发布:2024-11-26 07:56:25 浏览:355