當前位置:首頁 » 安卓系統 » 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 07:29:58 瀏覽:180
用電腦怎麼刷汽車行車電腦配置 發布:2024-11-26 07:24:14 瀏覽:688
客戶端ip和伺服器ip地址怎麼設置 發布:2024-11-26 07:18:25 瀏覽:684
如何破解加密的wmv 發布:2024-11-26 07:18:16 瀏覽:895
資源碼項目 發布:2024-11-26 07:10:12 瀏覽:892
acl配置第三步如何驗證 發布:2024-11-26 07:07:58 瀏覽:939
上傳gif搜索 發布:2024-11-26 06:27:05 瀏覽:763
linux用戶組文件 發布:2024-11-26 06:26:58 瀏覽:89
java介面編程 發布:2024-11-26 06:25:23 瀏覽:155
冪等編程 發布:2024-11-26 06:24:45 瀏覽:536