2013-08-15 2 views
0

나는 다음과 같은 코드가 있습니다변수에 날짜와 시간을 저장하는 방법은 무엇입니까?

Button schedend = FindViewById<Button>(Resource.Id.buttonschede); 
     schedend.Click += schedend_Click; 



    } 


    void schedend_Click(object sender, EventArgs e) 
    { 
     Dialog dialog = new Dialog(this); 
     dialog.SetContentView(Resource.Layout.DateTimePickerTemplate); 
     dialog.SetTitle("Pick date and time"); 
     TimePicker tp = FindViewById<TimePicker>(Resource.Id.timePicker1); 
     Button butadd = FindViewById<Button>(Resource.Id.buttonadd); 
     //tp.SetOnTimeChangedListener(onTimeChangedListener: retain()); 
     // tp.SetIs24HourView(new Boolean(true)); 
     butadd.Click += butadd_Click; 
     //tp.SetIs24HourView(true); 
     dialog.Show(); 
    } 
    private void retain() 
    { 

    } 
    void butadd_Click(object sender, EventArgs e) 
    { 

     EditText edittxt = FindViewById<EditText>(Resource.Id.editschstart); 

     edittxt.Text = e.ToString(); 

    } 

내가 날짜와 timepicker로, 사용자 정의 대화 상자가를

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/linearLayout1" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 
<ScrollView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 
    <LinearLayout 
     android:orientation="vertical" 
     android:minWidth="25px" 
     android:minHeight="25px" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/linearLayout2"> 
     <DatePicker 
      android:id="@+id/datePicker1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 
     <TimePicker 
      android:id="@+id/timePicker1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 
     <Button 
      android:text="Add" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/buttonadd" /> 
     <Button 
      android:text="Cancel" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/buttoncancel" /> 
    </LinearLayout> 
</ScrollView> 
</LinearLayout> 

나는 다른 방법을 시도,하지만 succes에에, 내가 어떻게 날짜를 유지할 수 있습니다 그리고 시간이 설정되어 변수에 유지하고 대화 상자에서 추가 버튼을 클릭하면 편집 문에 저장됩니다. 나는 이것에 초보적이며 약간의 도움이 필요합니다 .xh

답변

0

바라건대 나는 정확하게 당신이 질문하는 것을 이해하고 있습니다. TimePicker을 사용하여 사용자가 설정 한 데이터를 얻으려면 tp.getCurrentHour() 또는 tp.getCurrentMinute()과 같은 기본 제공 방법을 사용하면됩니다. 에서 사용할 수있는 방법의 전체 목록은 here 인 Android 설명서에 나와 있습니다. 해당 데이터를 EditText으로 설정하는 경우 edittxt.setText(yourVariableHere)이 필요합니다. 이 특별한 상황에서 TimePickerActivity의 개인 인스턴스 변수로 만드는 등 나머지 클래스에서 액세스 할 수있게 만들 수 있습니다. 그러면 에서 원하는 번호로 EditText을 설정할 수 있습니다.

+0

내가 매우 명확하지 않다면, Sry는 편집 텍스트를 설정하기 위해 시간과 날짜 (사용자가 설정)를 모두 가져 가고 싶다. –

+0

'TimePicker'는 단지 시간이라고 생각합니다. 만약 당신이 날짜를위한 인터페이스를 원한다면, 당신은'DatePicker'를 사용할 수 있습니다. 사용자가 'TimePicker'에서 선택한 시간을 검색하는 방법에 대한 내 대답을보다 명확히하는 방법을 모르겠습니다. 내가 너의 질문을 완전히 이해하지 않는 한. – Brian

+0

문제를 해결하기 위해 mydatePIcker.toShortdateString() + ""+ mytime.currentHour + ":"+ mytimepicker.currentMinute를 가져 와서 텍스트 상자에 설정하십시오! 고마워 ! :) –

관련 문제