0
私のアプリケーションでは、this libraryをカスタムカレンダービューに使用しています。クリックすると日付が共有され、次のアクティビティにその日付が渡されます。私は次の活動に日付を表示することができます。今私が欲しいのは、2つのボタンがあり、1つは "Previous"で、もう1つは "Next"です。任意のボタンをクリックすると、日付が要件に応じて変更されます。前回/次の日を取得する前回のアクティビティからSharedPreferencesを使用して日付を取得した後にボタンを押す日付
のonClick日付コードが
calendarView.setOnDateClickListener(new CalendarView.OnDateClickListener() {
@Override
public void onDateClick(@NonNull Date selectedDate) {
SimpleDateFormat df_new = new SimpleDateFormat("dd-MM-yyyy", Locale.getDefault());
String newselectedDate=df_new.format(selectedDate);
Toast.makeText(getApplicationContext(), "You selected" + newselectedDate + " : Date", Toast.LENGTH_SHORT).show();
// SharedPreferences for sharing the Date with Next Activity, Added by Tara
SimpleDateFormat s_day=new SimpleDateFormat("dd",Locale.getDefault()); String sdd=s_day.format(selectedDate);
SimpleDateFormat s_month=new SimpleDateFormat("MM",Locale.getDefault());String smm=s_month.format(selectedDate);
SimpleDateFormat s_year=new SimpleDateFormat("yyyy",Locale.getDefault());String syy=s_year.format(selectedDate);
SharedPreferences spf= getSharedPreferences("myprfs", Context.MODE_PRIVATE);
SharedPreferences.Editor spe = spf.edit();
// spe.putString("sdate", String.valueOf(selectedDate));
spe.putString("sday", String.valueOf(sdd));
spe.putString("smonth", String.valueOf(smm));
spe.putString("syear", String.valueOf(syy));
Log.d("Day is", String.valueOf(sdd));
Log.d("Month is", String.valueOf(smm));
Log.d("Year is", String.valueOf(syy));
spe.commit();
Intent i_available_slot=new Intent(BookAnAppoinment.this, ChangeDate.class);
startActivity(i_available_slot);
}
});
であると私は共有好みを通じて日付を取得しています次の活動は、私は私の通りtry/catchブロックが、コードにできないと書いた
SharedPreferences spf=getSharedPreferences("myprfs", Context.MODE_PRIVATE);
String id1 = spf.getString("sday", "no value");
String id2 = spf.getString("smonth", "no value");
String id3 = spf.getString("syear", "no value");
String sdate=id1+"-"+id2+"-"+id3;
// d.setText(sdate);
final SimpleDateFormat df = new SimpleDateFormat("dd-MMM-yyyy");
final String formattedDate = df.format(sdate);
d.setText(formattedDate);
try {
Date date=df.parse(sdate);
Calendar cal = df.getCalendar();
} catch (ParseException e) {
e.printStackTrace();
}
n.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
p.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
です要件。私を助けてください。