title: How to get variable from another inner class for globally use
body: <p>This is my code. Where have an inner class named <code>BirthDatePickerFragment</code>. I want to call globally <code>birthYear</code>, <code>birthMonth</code>, <code>birthDay</code> variables form  <code>onCreateDialog</code> method which is under <code>BirthDatePickerFragment</code>.</p>
  
  <p><code>MainActivity.java</code></p>
  
  <pre><code>import androidx.appcompat.app.AppCompatActivity;
  import android.app.AlertDialog;
  import android.app.DatePickerDialog;
  import android.app.Dialog;
  import android.app.DialogFragment;
  import android.os.Bundle;
  import android.text.TextUtils;
  import android.view.View;
  import android.widget.Button;
  import android.widget.DatePicker;
  import android.widget.EditText;
  import android.widget.TextView;
  import android.widget.Toast;
  
  import java.text.DateFormat;
  import java.util.Calendar;
  import java.util.Date;
  
  public class MainActivity extends AppCompatActivity implements View.OnClickListener {
  
      Button birthDatePickerButton;
  
      TextView calculateTextView;
  
      EditText birthDayDatePickerEditText;
  
  @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          birthDatePickerButton = findViewById(R.id.birthDatePickerBT);
          birthDayDatePickerEditText = findViewById(R.id.birthDayDatePickEditTextID);
          calculateTextView=findViewById(R.id.calculateTextViewID);
  
          birthDatePickerButton.setOnClickListener(this);
  
      }
  
  
   public void onClick(View v) {
  
  
              // Initialize a new date picker dialog fragment
               DialogFragment dFragment = new BirthDatePickerFragment();
  
               // Show the date picker dialog fragment
               dFragment.show(getFragmentManager(), "Date Picker");
  
  
          }
  
  
  
  public static class BirthDatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener {
  
  
          @Override
          public Dialog onCreateDialog(Bundle savedInstanceState) {
              final Calendar calendar = Calendar.getInstance();
              int birthYear = calendar.get(Calendar.YEAR);
              int birthMonth = calendar.get(Calendar.MONTH);
              int birthDay = calendar.get(Calendar.DAY_OF_MONTH);
  
  
              DatePickerDialog datePickerDialog = new DatePickerDialog(getActivity(),
                      AlertDialog.THEME_TRADITIONAL, this, birthYear, birthMonth,birthDay);
              return datePickerDialog;
          }
  
  
          public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
  
              // Do something with the chosen date
              EditText birthDatText=getActivity().findViewById(R.id.birthDayDatePickEditTextID);
  
  
              // Create a Date variable/object with user chosen date
              Calendar cal = Calendar.getInstance();
              cal.setTimeInMillis(0);
              cal.set(year, month, dayOfMonth, 0, 0, 0);
              Date chosenDate = cal.getTime();
  
              // Format the date using style short
              DateFormat df_short = DateFormat.getDateInstance(DateFormat.SHORT);
              String df_short_str = df_short.format(chosenDate);
              // Display the formatted date
              birthDatText.setText(df_short_str);
  
  
            }
  </code></pre>