으로 선언 된 메소드에서 값을 가져온다 안녕하세요 저는 Android와 Java에 익숙하지 않습니다. DialogFragment
을 확장하고 DatePickerDialog.OnDateSetListener
을 구현하는 Date Picker Fragment 클래스를 작성 중입니다.이 메소드는 public void onDateSet(DatePicker view, int year, int month, int day)
인데이를 선언해야합니다. 새 날짜를 public
String
변수로 설정하십시오.public void
주된 활동에 public String
변수를 사용하면 TextView
에 값을 표시 할 수 있습니까? 그렇다면 어떻게?
내 주요 활동 코드는 다음과 같습니다
public class TARForm extends AppCompatActivity implements CompoundButton.OnCheckedChangeListener {
EditText departuredate;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tarform);
departuredate = (EditText) findViewById(R.id.departure_date);
}
public void showDatePickerDialog(View v) {
DialogFragment newFragment = new DatePickerFragment();
newFragment.show(getFragmentManager(), "datePicker");
}
}
그리고DatePickerFragment
코드 것은 :
public class DatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener{
int selectyear, selectmonth, selectday;
public String date;
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current date as the default date in the picker
final Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
return new DatePickerDialog(getActivity(), this, year, month, day);
}
public void onDateSet(DatePicker view, int year, int month, int day) {
selectday = day;
selectmonth = month+1;
selectyear = year;
date = selectday + "-" + selectmonth + "-" + selectyear;
}
}
당신은 내가 "날짜를 얻을 수있는 방법이 정보로 안내 할 수있는 경우 "MainActivity로 출발 했습니까? 감사.
주 활동 및 단편 클래스의 코드를 공유하고 있습니다. 도와주세요. – rodaxyz
당신은'OnDismissListener'를 사용할 수 있습니다, 이것을 확인해야합니다 [답변] (http://stackoverflow.com/a/23786151/5769824) – Hmm
인터페이스/콜백 사용 – Rahul