android 日历 天 小时,java – 如何在android中设置日历特定的小时

我不想添加年份或月份。每天的时间,分钟和秒数。

如何使用它的Calendar对象呢?

这是我的代码

// get a Calendar object with current time

Calendar cal = Calendar.getInstance();

// add 5 minutes to the calendar object

cal.add(Calendar.HOUR, 4);

cal.add(Calendar.MINUTE, 40);

Intent i = new Intent(this, Receiver.class);

i.putExtra("alarm_message", "O'Doyle Rules!");

// In reality, you would want to have a static variable for the request code instead of 192837

PendingIntent sender = PendingIntent.getBroadcast(this, 192837, i, PendingIntent.FLAG_UPDATE_CURRENT);

// Get the AlarmManager service

AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);

am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), sender);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我可以帮您解答问题。为了在Android Studio编写可交互的日历页面,您可以使用Java语言和以下组件: 1. CalendarView:这是一个内置的Android组件,可以在应用程序实现日历视图。 2. DatePicker:这是另一个内置的Android组件,可让用户选择日期。 3. RecyclerView:这是一个用于显示列表数据的Android组件,可以用于显示日历的日期。 首先,您需要创建一个布局文件,其包含这些组件。然后,在Java代码,您可以使用CalendarView和DatePicker来处理日期选择,并使用RecyclerView显示所选日期的详细信息。 以下是一个简单的示例代码: 布局文件: ``` <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <CalendarView android:id="@+id/calendarView" android:layout_width="match_parent" android:layout_height="wrap_content"/> <DatePicker android:id="@+id/datePicker" android:layout_width="match_parent" android:layout_height="wrap_content"/> <androidx.recyclerview.widget.RecyclerView android:id="@+id/recyclerView" android:layout_width="match_parent" android:layout_height="wrap_content"/> </LinearLayout> ``` Java代码: ``` public class MainActivity extends AppCompatActivity { private CalendarView calendarView; private DatePicker datePicker; private RecyclerView recyclerView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); calendarView = findViewById(R.id.calendarView); datePicker = findViewById(R.id.datePicker); recyclerView = findViewById(R.id.recyclerView); calendarView.setOnDateChangeListener(new CalendarView.OnDateChangeListener() { @Override public void onSelectedDayChange(@NonNull CalendarView view, int year, int month, int dayOfMonth) { // 在这里处理日历日期选择 // 显示所选日期的详细信息 } }); datePicker.setOnDateChangedListener(new DatePicker.OnDateChangedListener() { @Override public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) { // 在这里处理日期选择 // 显示所选日期的详细信息 } }); // 在这里使用RecyclerView显示所选日期的详细信息 } } ``` 希望这可以帮助您。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值