我有2个图像按钮和2个textviews。下面的代码将相同的日期写入我不想要的2个textviews,当我单击一个图像按钮意味着写入edittext1时,当单击第二个时,它应该写入edittext2
这是我的代码
public void selectDate(View view) {
DialogFragment newFragment = new SelectDateFragment();
newFragment.show(getSupportFragmentManager(), "DatePicker");
}
public void populateSetDate(int year, int month, int day) {
DepartDate = (TextView)findViewById(R.id.editText1);
DepartDate.setText(month+"/"+day+"/"+year);
}
public void populateSetDate1(int year1, int month1, int day1) {
ReturnDate = (TextView)findViewById(R.id.editText2);
ReturnDate.setText(month1+"/"+day1+"/"+year1);
}
public class SelectDateFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final Calendar calendar = Calendar.getInstance();
int yy = calendar.get(Calendar.YEAR);
int mm = calendar.get(Calendar.MONTH);
int dd = calendar.get(Calendar.DAY_OF_MONTH);
return new DatePickerDialog(getActivity(), this, yy, mm, dd);
}
public void onDateSet(DatePicker view, int yy, int mm, int dd) {
populateSetDate(yy, mm+1, dd);
populateSetDate1(yy, mm+1, dd);
}
答案 0 :(得分:0)
public void selectDate(View view) {
DialogFragment newFragment = new SelectDateFragment(view);
newFragment.show(getSupportFragmentManager(), "DatePicker");
}
public void populateSetDate(int year, int month, int day, View v) {
DepartDate = v;
DepartDate.setText(month+"/"+day+"/"+year);
}
public class SelectDateFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener {
private View view;
public SelectDateFragment(View view) {
this.view = view;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final Calendar calendar = Calendar.getInstance();
int yy = calendar.get(Calendar.YEAR);
int mm = calendar.get(Calendar.MONTH);
int dd = calendar.get(Calendar.DAY_OF_MONTH);
return new DatePickerDialog(getActivity(), this, yy, mm, dd);
}
public void onDateSet(DatePicker view, int yy, int mm, int dd) {
populateSetDate(yy, mm+1, dd);
populateSetDate1(yy, mm+1, dd);
}