0

我有 2 个图像按钮和 2 个文本视图。以下代码将相同的日期写入我不想要的 2 个文本视图,当我单击一个图像按钮时,它意味着写入 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);

        }
4

1 回答 1

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);

    }
于 2013-04-25T15:45:38.190 回答