If next button is clicked, its data should go to formattedDate I have tried several times and it keeps giving me an error.
next.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
Calendar c = Calendar.getInstance();
c.add(Calendar.DATE, 1);
System.out.println("Current time => " c.getTime());
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
String formattedDate = df.format(c.getTime());
textView.setText(formattedDate);
post.recipe_time = formattedDate;
}
});
this formattedDate error how to clear
private void requestHomeData2() {
ApiInterface apiInterface =
RestAdapter.createAPI(sharedPref.getApiUrl());
callbackCall2 =
apiInterface.getDate(formattedDate,AppConfig.REST_API_KEY);
this.callbackCall2.enqueue(new Callback<Callbackdate>() {
public void onResponse(Call<Callbackdate> call,
Response<Callbackdate> response) {
Callbackdate responseHome = response.body();
if (responseHome == null || !responseHome.status.equals("ok")) {
onFailRequest();
return;
}
displayData2(responseHome);
swipeProgress(false);
lyt_main_content.setVisibility(View.VISIBLE);
}
public void onFailure(Call<Callbackdate> call, Throwable th) {
Log.e("onFailure", th.getMessage());
if (!call.isCanceled()) {
onFailRequest();
}
}
});
}
CodePudding user response:
Set your String formattedDate
variable as global variable and initialize it like String formattedDate = ""
, then assign value formattedDate = df.format(c.getTime());
in your next button click and then invoke requestHomeData2
wherever you need it.