2010-04-08 5 views
1

내 앱의 인 텐트를 선언하는 데 문제가 있습니다. 텍스트 필드와 회 전자가있는 양식이 있습니다. onClick이 Datepicker를 표시해야하는 버튼을 추가했습니다. DatePicker를 새로운 클래스로 선언하고 onclick 인 텐트에 추가했습니다.android에서 의도 필터 선언

date.setOnClickListener(new View.OnClickListener() { 
    public void onClick(View view) 
    { 
     Intent i=new Intent(SendMail.this,DatePicker.class); 

     startActivity(i); 

    } 
}); 

는 매니페스트에서 나는 모든 형태의 리셋을 받고 버튼을 클릭하고 모든 스피너 값이 사라지고 때 문제가 지금

<activity android:name=".DatePicker"> 

     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 

을 선언했다. 이는 의도를 잘못 선언했기 때문입니다. 그래서, 내 의도를 선언하는 방법을 지정할 수 있도록 DatePicker가 주 양식 자체에서 호출됩니다.

답변

1

날짜 선택기 결과에 대한 새 활동이 필요하지 않습니다. 대신 startActivity를 실행의 이러한 구성 요소를 가지고 당신의 SendMail 클래스를 확인

...

public class SendMail extends Activity { 

static final int DATE_DIALOG_ID = 1; 

// date and time 
private int mYear; 

private int mMonth; 

private int mDay; 

public void launchSetDate() { 
     showDialog(DATE_DIALOG_ID); 
} 
@Override 
protected Dialog onCreateDialog(int id) { 
     switch (id) { 

      case DATE_DIALOG_ID: 
       return new DatePickerDialog(this, mDateSetListener, mYear, mMonth, mDay); 
     } 
     return null; 
} 
@Override 
protected void onPrepareDialog(int id, Dialog dialog) { 
     switch (id) { 
      case DATE_DIALOG_ID: 
       ((DatePickerDialog) dialog).updateDate(mYear, mMonth, mDay); 
       break; 
     } 
} 
    private DatePickerDialog.OnDateSetListener mDateSetListener = new DatePickerDialog.OnDateSetListener() { 

     public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { 
      mYear = year; 
      mMonth = monthOfYear; 
      mDay = dayOfMonth; 
      // do something with the result 
     } 
    }; 
} 

그런 다음 방법 launchSetDate()를 호출;

+0

지금 내 보내면 ... 감사합니다. 나는 약간의 텍스트를 가지고 그것을 우편으로 보낸다. Object.getText(). toString()을 사용하여 문자열을 가져옵니다. 마찬가지로 어떻게 날짜의 값을 얻을 수 있습니까? ??? –

+0

onDateSet 이벤트가 있고 mYear, mMonth, mDay를 사용하여 원하는 날짜를 계산할 수 있습니다. – Pentium10