Hi,
I have a datepicker dialog fragment and on the OnDateSetListener function I am trying to change the text on a button in one of my views but this isn't working for some reason, why is this? Here's my code for my DateDialog.java file
I have a datepicker dialog fragment and on the OnDateSetListener function I am trying to change the text on a button in one of my views but this isn't working for some reason, why is this? Here's my code for my DateDialog.java file
Java:
package com.example.myapplication2017;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.app.DatePickerDialog;
import android.view.ViewDebug;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.TextView;
import android.widget.Toast;
import java.util.Calendar;
import java.util.zip.Inflater;
public class DateDialog extends DialogFragment {
private View dialogView;
private int year, month, day;
private Calendar calendar;
@Override
public Dialog onCreateDialog(Bundle savedInstanceState){
calendar = Calendar.getInstance();
year = calendar.get(Calendar.YEAR);
month = calendar.get(Calendar.MONTH) + 1;
day = calendar.get(Calendar.DAY_OF_MONTH);
return new DatePickerDialog(getActivity(), dpListener, year, month, day);
}
private DatePickerDialog.OnDateSetListener dpListener = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker arg0, int year, int month, int day) {
// TODO Auto-generated method stub
// arg1 = year
// arg2 = month
// arg3 = day
Bundle bundle = new Bundle();
bundle.putInt("selectedYear", year);
bundle.putInt("selectedMonth", month);
bundle.putInt("selectedDay", day);
Log.i("Day = ", Integer.toString(day));
Log.i("Month = ", Integer.toString(month + 1));
Log.i("Yesr = ", Integer.toString(year));
LayoutInflater inflater = (LayoutInflater) getActivity().getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View activity1View = inflater.inflate(R.layout.activity_1, null);
TextView textViewDateSelected = (TextView) activity1View.findViewById(R.id.textViewDateSelected);
textViewDateSelected.setText(Integer.toString(day) + "/" + Integer.toString(month + 1) + "/" + Integer.toString(year));
try {
LayoutInflater inflaterActivity3 = (LayoutInflater) getActivity().getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View viewActivity3 = inflaterActivity3.inflate(R.layout.activity_3, null);
Button btnSendMsgOn = (Button) viewActivity3.findViewById(R.id.button4);
//btnSendMsgOn.setText(Integer.toString(day) + "/" + Integer.toString(month + 1) + "/" + Integer.toString(year));
btnSendMsgOn.setText(bundle.getInt("selectedYear") + "/" + bundle.getInt("selectedMonth") + "/" + bundle.getInt("selectedDay"));
}
catch (Exception ex ){
Log.i("Button error msg", ex.getMessage());
}
}
};
}