如何为“TODAYS DATE”的日历视图设置 onclick 监听器?该代码适用于 onclick 昨天或明天的日期,但不适用于今天的日期?有人可以帮忙吗?
代码:
MainActivity.java:
final CalendarView calendarview=(CalendarView)findViewById(R.id.Calendarview);
final Button selectDate=(Button)findViewById(R.id.Date_seletcion_btn);
selectDate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
calendarview.setVisibility(View.VISIBLE);
}
});
calendarview.setClickable(true);
//calendarview.getSelectedDateVerticalBar();
/*calendarview.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {
@Override
public void onSelectedDayChange(CalendarView calendarview, int year, int month,
int day) {
// TODO Auto-generated method stub
int day1, month1, year1;
day1=day;
month1=month;
year1=year;
Calendar calendar=Calendar.getInstance();
clickeddate=calendarview.getDate();
calendar.setTimeInMillis(clickeddate);
//ArrayList<> array=calendar.getTouchables();
Toast.makeText(getApplicationContext(), "Date Selected: " + day,Toast.LENGTH_LONG).show();
Intent homein=new Intent(getApplicationContext(),HomePageActivity.class);
homein.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
homein.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(homein);
finish();
}
}); */
**XML 代码:**
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/Calendar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="120dp"
android:gravity="center_horizontal"
android:orientation="vertical" >
<!--
<LinearLayout
android:id="@+id/Calendar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"></LinearLayout>
-->
<Button
android:id="@+id/Date_seletcion_btn"
style="?android:attr/borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:layout_marginTop="20dp"
android:background="@drawable/button_states"
android:text="@string/calendarselection" />
<!--
<DatePicker
android:id="@+id/datepicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
/>
-->
<CalendarView
android:id="@+id/Calendarview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:visibility="gone"
android:clickable="true" />
</LinearLayout>