Calendar 禁用Applandeo日历中的转发和上一个侦听器
我正在使用Applandeo日历,我显示了一个虚拟事件列表。我的问题是,我想禁用forward和previous侦听器,这样,如果他单击forward和previous按钮,它应该什么都不做。基本上,它应该被禁用,因为我想根据我的微调器选择月份,而不是日历的滚动。我可以找到calendarView.setSwipeEnabled(false);而且效果很好。但由于前进和前进按钮仍然存在,用户仍然可以更改月份。 在setonforward和setprevious clicklisteners中我应该做什么 我找不到任何与它有关的东西 主要活动Calendar 禁用Applandeo日历中的转发和上一个侦听器,calendar,event-listener,Calendar,Event Listener,我正在使用Applandeo日历,我显示了一个虚拟事件列表。我的问题是,我想禁用forward和previous侦听器,这样,如果他单击forward和previous按钮,它应该什么都不做。基本上,它应该被禁用,因为我想根据我的微调器选择月份,而不是日历的滚动。我可以找到calendarView.setSwipeEnabled(false);而且效果很好。但由于前进和前进按钮仍然存在,用户仍然可以更改月份。 在setonforward和setprevious clicklisteners中我应
package com.example.exoplayer;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.os.Bundle;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import com.applandeo.materialcalendarview.CalendarView;
import com.applandeo.materialcalendarview.EventDay;
import com.applandeo.materialcalendarview.exceptions.OutOfDateRangeException;
import com.applandeo.materialcalendarview.listeners.OnCalendarPageChangeListener;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
public class CalendarActivity extends AppCompatActivity {
Spinner spinner;
String monthValue;
List<EventDay> events = new ArrayList<>();
List<EventDay> presentList = new ArrayList<>();
List<EventDay> absentList = new ArrayList<>();
CalendarView calendarView;
TextView textView_noofdays_present, textView_noofdays_absent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_calendar);
calendarView = (CalendarView) findViewById(R.id.calendarView);
textView_noofdays_present = (TextView) findViewById(R.id.textView_noofdays_present);
textView_noofdays_absent = (TextView) findViewById(R.id.textView_noofdays_absent);
spinner = (Spinner) findViewById(R.id.spinner);
try {
//serverCall_get_attedancedetails();
}
catch (Exception e) {
Log.d("cknviewAttendanceError",e.getMessage());
}
//-------today date-----
Calendar calendarToday = Calendar.getInstance();
try {
calendarView.setDate(calendarToday);
} catch (OutOfDateRangeException e) {
e.printStackTrace();
}
setCalendarStyle();
//populate the spinner and attach it to spinner of xml
ArrayList<String> monthList = new ArrayList<String>();
monthList.add("-Select Month-");
monthList.add("January");
monthList.add("February");
monthList.add("March");
monthList.add("April");
monthList.add("May");
monthList.add("June");
monthList.add("July");
monthList.add("August");
monthList.add("September");
monthList.add("October");
monthList.add("November");
monthList.add("December");
ArrayAdapter<String> typeDataAdapter = new ArrayAdapter<String>(CalendarActivity.this, android.R.layout.simple_spinner_item, monthList);
typeDataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(typeDataAdapter);
//when we click a particular plan, the plan is stored in a variable
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
monthValue = spinner.getSelectedItem().toString();
Log.d("spinner month value: ",monthValue);
setCalendarData(monthValue);
}
public void onNothingSelected(AdapterView<?> adapterView) {
return;
}
});
}
public void setCalendarStyle() {
calendarView.setSwipeEnabled(false);
calendarView.setOnForwardPageChangeListener(new OnCalendarPageChangeListener() {
@Override
public void onChange() {
}
});
calendarView.setOnPreviousPageChangeListener(new OnCalendarPageChangeListener() {
@Override
public void onChange() {
}
});
}
public void setCalendarData(String selectedMonth) {
Calendar selectedCalendar = Calendar.getInstance();
selectedCalendar.set(Calendar.DAY_OF_MONTH, 1);
if(selectedMonth.equals("January"))
selectedCalendar.set(Calendar.MONTH, Calendar.JANUARY);
else if(selectedMonth.equals("February"))
selectedCalendar.set(Calendar.MONTH, Calendar.FEBRUARY);
else if(selectedMonth.equals("March"))
selectedCalendar.set(Calendar.MONTH, Calendar.MARCH);
else if(selectedMonth.equals("April"))
selectedCalendar.set(Calendar.MONTH, Calendar.APRIL);
else if(selectedMonth.equals("May"))
selectedCalendar.set(Calendar.MONTH, Calendar.MAY);
else if(selectedMonth.equals("June"))
selectedCalendar.set(Calendar.MONTH, Calendar.JUNE);
else if(selectedMonth.equals("July"))
selectedCalendar.set(Calendar.MONTH, Calendar.JULY);
else if(selectedMonth.equals("August"))
selectedCalendar.set(Calendar.MONTH, Calendar.AUGUST);
else if(selectedMonth.equals("September"))
selectedCalendar.set(Calendar.MONTH, Calendar.SEPTEMBER);
else if(selectedMonth.equals("October"))
selectedCalendar.set(Calendar.MONTH, Calendar.OCTOBER);
else if(selectedMonth.equals("November"))
selectedCalendar.set(Calendar.MONTH, Calendar.NOVEMBER);
else if(selectedMonth.equals("December"))
selectedCalendar.set(Calendar.MONTH, Calendar.DECEMBER);
//selectedCalendar.set(Calendar.YEAR,2020);
try {
calendarView.setDate(selectedCalendar);
} catch (OutOfDateRangeException e) {
e.printStackTrace();
}
//-------present data-----
for (int i = 1; i <= 5; i++) {
Calendar calendar = Calendar.getInstance();
calendar.set(2020, 8, i);
events.add(new EventDay(calendar, R.drawable.present));
presentList.add(new EventDay(calendar, R.drawable.present));
}
//-------absent data-----
for (int i = 7; i < 10; i++) {
Calendar calendar = Calendar.getInstance();
calendar.set(2020, 8, i);
events.add(new EventDay(calendar, R.drawable.absent));
absentList.add(new EventDay(calendar, R.drawable.absent));
}
Log.d("ckneventList", "check: " + events.size());
Log.d("cknpresentList", "check: " + presentList.size());
Log.d("cknabsentList", "check: " + absentList.size());
calendarView.setEvents(events);
//-------show calendar data on texts-----
if (presentList.size() > 1)
textView_noofdays_present.setText(presentList.size() + " days");
else
textView_noofdays_present.setText(presentList.size() + " day");
if (absentList.size() > 1)
textView_noofdays_absent.setText(absentList.size() + " days");
else
textView_noofdays_absent.setText(absentList.size() + " day");
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
onBackPressed();
return true;
}
return super.onOptionsItemSelected(item);
}
}
package com.example.exoplayer;
导入androidx.appcompat.app.appcompat活动;
导入androidx.appcompat.widget.Toolbar;
导入android.os.Bundle;
导入android.util.Log;
导入android.view.MenuItem;
导入android.view.view;
导入android.widget.AdapterView;
导入android.widget.ArrayAdapter;
导入android.widget.Spinner;
导入android.widget.TextView;
导入android.widget.Toast;
导入com.applandeo.materialcalendarview.CalendarView;
导入com.applandeo.materialcalendarview.EventDay;
导入com.applandeo.materialcalendarview.exceptions.OutOfDaterRangeException;
导入com.applandeo.materialcalendarview.listeners.OnCalendarPageChangeListener;
导入java.util.ArrayList;
导入java.util.Calendar;
导入java.util.List;
公共类CalendarActivity扩展了AppCompatActivity{
纺纱机;
字符串monthValue;
列表事件=新建ArrayList();
List presentList=new ArrayList();
List absentList=new ArrayList();
日历视图日历视图;
TextView TextView_noofdays_出席,TextView_noofdays_缺席;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u日历);
calendarView=(calendarView)findViewById(R.id.calendarView);
textView\u noofdays\u present=(textView)findViewById(R.id.textView\u noofdays\u present);
textView\u noofdays\u缺席=(textView)findViewById(R.id.textView\u noofdays\u缺席);
微调器=(微调器)findViewById(R.id.spinner);
试一试{
//serverCall_get_AttendanceDetails();
}
捕获(例外e){
Log.d(“cknviewAttendanceError”,e.getMessage());
}
//-------今日日期-----
Calendar calendarToday=Calendar.getInstance();
试一试{
calendarView.setDate(calendarToday);
}捕获(OutofDaterRange例外){
e、 printStackTrace();
}
setCalendarStyle();
//填充微调器并将其附加到xml的微调器
ArrayList monthList=新建ArrayList();
月列表。添加(“-选择月-”;
月份列表。添加(“一月”);
月份列表。添加(“二月”);
月份列表。添加(“三月”);
月份列表。添加(“四月”);
月清单。添加(“五月”);
月份列表。添加(“六月”);
月清单。添加(“7月”);
月份列表添加(“八月”);
月列表添加(“9月”);
月清单。添加(“10月”);
月清单。添加(“11月”);
月份列表添加(“12月”);
ArrayAdapter typeDataAdapter=新的ArrayAdapter(CalendarActivity.this,android.R.layout.simple\u spinner\u项目,monthList);
typeDataAdapter.setDropDownViewResource(android.R.layout.simple\u微调器\u下拉项);
spinner.setAdapter(typeDataAdapter);
//单击特定计划时,该计划存储在变量中
spinner.setOnItemSelectedListener(新的AdapterView.OnItemSelectedListener(){
已选择公共视图(AdapterView AdapterView、View视图、int i、long l){
monthValue=spinner.getSelectedItem().toString();
Log.d(“微调器月值:”,月值);
设置日历数据(monthValue);
}
未选择公共无效(AdapterView AdapterView){
返回;
}
});
}
公共void setCalendarStyle(){
calendarView.setSwipeEnabled(假);
calendarView.setOnForwardPageChangeListener(新的OnCalendarPageChangeListener(){
@凌驾
更改后的公共无效(){
}
});
calendarView.setOnPreviousPageChangeListener(新OnCalendarPageChangeListener()){
@凌驾
更改后的公共无效(){
}
});
}
public void setCalendarData(字符串selectedMonth){
Calendar selectedCalendar=Calendar.getInstance();
selectedCalendar.set(Calendar.DAY\u OF_MONTH,1);
如果(选择月等于(“一月”))
selectedCalendar.set(Calendar.MONTH、Calendar.JANUARY);
else if(选择月等于(“二月”))
selectedCalendar.set(Calendar.MONTH、Calendar.二月);
else if(选择月等于(“三月”))
已选择Calendar.set(Calendar.MONTH、Calendar.MARCH);
else if(选择月等于(“四月”))
selectedCalendar.set(Calendar.MONTH、Calendar.APRIL);
else if(选择月等于(“五月”))
selectedCalendar.set(Calendar.MONTH、Calendar.MAY);
else if(选择月等于(“六月”))
selectedCalendar.set(Calendar.MONTH、Calendar.JUNE);
else if(选择月等于(“七月”))
selectedCalendar.set(Calendar.MONTH、Calendar.JULY);
else if(选择月等于(“八月”))
selectedCalendar.set(Calendar.MONTH、Calendar.AUGUST);
else if(选择月等于(“九月”))
selectedCalendar.set(Calendar.MONTH、Calendar.Septer);
else if(选择月等于(“十月”))
selectedCalendar.set(Calendar.MONTH、Calendar.十月);
else if(选择月等于(“十一月”))
selectedCalendar.set(Calendar.MONTH、Calendar.11th);
else if(选择月等于(“十二月”))
selectedCalendar.set(
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@color/white"
android:orientation="vertical"
xmlns:card_view="http://schemas.android.com/apk/res-auto">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Choose month"
android:layout_gravity="center"
android:gravity="center"
android:layout_margin="5dp"
android:textSize="18sp"
android:textColor="#000000"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_margin="10dp"
android:background="@drawable/spinner_border"
android:orientation="horizontal">
<Spinner
android:id="@+id/spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:background="@android:color/transparent"
android:gravity="center"
android:layout_marginLeft="5dp"
android:spinnerMode="dropdown" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:src="@drawable/ic_down"
android:paddingRight="10dp"/>
</RelativeLayout>
<com.applandeo.materialcalendarview.CalendarView
android:id="@+id/calendarView"
android:layout_width="match_parent"
android:layout_height="400dp"
android:layout_margin="5dp"
app:todayLabelColor="@color/lightred"
app:headerColor="@color/actn_gray_dark"
app:headerLabelColor="@color/grey"
app:abbreviationsBarColor="@color/colorAccent"
app:abbreviationsLabelsColor="@color/white"
app:pagesColor="@color/white"
app:selectionLabelColor="@color/black"
app:disabledDaysLabelsColor="@color/grey"
app:forwardButtonSrc="@drawable/ic_nothing"
app:previousButtonSrc="@drawable/ic_nothing"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:orientation="vertical"
android:layout_gravity="center"
android:gravity="center">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
card_view:cardCornerRadius="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:padding="10dp"
android:text="Your Attendance Report"
android:layout_gravity="center"
android:gravity="center"
android:textColor="@color/black"
android:textSize="18sp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:orientation="vertical"
android:layout_weight="1">
<TextView
android:id="@+id/textView_noofdays_present"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:padding="10dp"
android:text="2 days"
android:layout_gravity="center"
android:gravity="center"
android:textColor="@color/black"
android:textSize="18sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:padding="10dp"
android:layout_gravity="center"
android:gravity="center"
android:text="PRESENT"
android:background="@drawable/rounded_button_green"
android:textColor="@color/white"
android:textSize="18sp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:orientation="vertical"
android:layout_weight="1">
<TextView
android:id="@+id/textView_noofdays_absent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:padding="10dp"
android:text="1 day"
android:layout_gravity="center"
android:gravity="center"
android:textColor="@color/black"
android:textSize="18sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:padding="10dp"
android:layout_gravity="center"
android:gravity="center"
android:text="ABSENT"
android:background="@drawable/rounded_button_red"
android:textColor="@color/white"
android:textSize="18sp"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>