2013-04-25 2 views
0

2 개의 이미지 버튼과 2 개의 텍스트 뷰가 있습니다. 내가 하나 개의 이미지 버튼을 edittext1에 기록하기위한 것입니다 클릭하고 두 번째 클릭 할 때 edittext2 여기날짜 선택 도구를 2 개의 텍스트 뷰로 복사하는 것을 중지해야합니다.

내 코드

입니다에 작성해야하는 경우 다음 코드는 내가 원하는 해달라고 2 textviews에 같은 날짜를 기록
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

두 가지 메소드를 호출합니다. 'populateSetDate (yy, mm + 1, dd); populateSetDate1 (yy, mm + 1, dd);'in 날짜 설정 – Pragnani

답변

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

    } 
+0

datepicker를 표시하는 imagebutton을 사용하여 두 개의 텍스트 영역에 쓰려면 datepicker가 필요합니다. 2 textareas 및 2 datepickers 있습니다. 1 완벽하게 작동하지만 두 번째 텍스트 영역을 추가하려고하면 첫 번째 텍스트 영역을 덮어 쓰고 두 번째 텍스트 영역에 추가합니다. 아무도 내 코드를 바꿀 수있는 아이디어가있어. 위의 내용은 내가 묻는 것을하지는 않지만 어쨌든 감사합니다! –

+0

오른쪽 청취자를 올바른 이미지 버튼에 묶어 두었습니까? – Weibo

+0

첫 번째 이미지 버튼은 내가 제공 한 코드와 완벽하게 작동하기 때문에 첫 번째 이미지 버튼이 호출되는 곳이 확실하지 않습니다. 누군가가 그것이 내가 두 번째 것을 위해 또 다른 것을 추가 할 수있는 곳을 지적 할 수 있기를 바랐다. 나는 그때 문제를 해결할 것이라고 생각한다. –

관련 문제