ユーザーが「生年月日フィールド」をクリックしたときにカレンダーを持つ別のページまたはポップアップボックスに移動するため、ユーザーが「生年月日」フィールドを選択できるようにする簡単なカレンダーを追加するにはどうすればよいですか?彼/彼女の誕生日?私はPhoneGap 1.4.1でEclipseでAndroidアプリケーションを開発しています。多くの皆さんありがとうございました。ここで生年月日登録ページ、Eclipse
0
A
答えて
2
は私がやったことです:
デフォルト値に設定するには、カレンダーのインスタンスを作成します。
//class level variables
private int mYear;
private int mMonth;
private int mDay;
static final int DATE_DIALOG_ID = 0;
private DatePickerDialog.OnDateSetListener mDateSetListener;
//inside onCreate
final Calendar c = Calendar.getInstance();
mYear = c.get(Calendar.YEAR)-20;
mMonth = c.get(Calendar.MONTH);
mDay = c.get(Calendar.DAY_OF_MONTH); //Default DOB is (today - 20) years
//date picker things
mDateSetListener = new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
mYear = year;
mMonth = monthOfYear;
mDay = dayOfMonth;
updateDisplay();
}
};
機能出生のEditTextフィールドの日付を更新する:
private void updateDisplay() {
et_dob.setText(new StringBuilder().append(mMonth+1).append("/").append(mDay).append("/").append(mYear).append(" "));
//month is 0 based so 1 is added in mMonth;
}
onClickListener et_dob
showDialog(DATE_DIALOG_ID); //DATE_DIALOG_ID = 0;
に続いて、あなたの活動にonCreateDialogオーバーライドします。
@Override
protected Dialog onCreateDialog(int id) {
// TODO Auto-generated method stub
switch (id) {
case DATE_DIALOG_ID:
return new DatePickerDialog(this,
mDateSetListener,
mYear, mMonth, mDay);
}
return null;
}
EditText et_dobをクリックすると、このような画面が表示されます。あなたがcalender..iのポップアップが開きますアダプターをしなければならない
0
package com.timesoft;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import android.app.Activity;
import android.content.Context;
import android.graphics.Typeface;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.wheel.ArrayWheelAdapter;
import com.wheel.NumericWheelAdapter;
import com.wheel.OnWheelChangedListener;
import com.wheel.WheelView;
public class Popup_Date extends Activity {
/** Called when the activity is first created. */
WheelView month;
WheelView year;
WheelView day;
String months[];
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.popup_date);
Calendar calendar = Calendar.getInstance();
month = (WheelView) findViewById(R.id.month);
year = (WheelView) findViewById(R.id.year);
day = (WheelView) findViewById(R.id.day);
OnWheelChangedListener listener = new OnWheelChangedListener() {
public void onChanged(WheelView wheel, int oldValue, int newValue) {
updateDays(year, month, day);
}
};
// month
int curMonth = calendar.get(Calendar.MONTH);
months= new String[] { "January", "February", "March",
"April", "May", "June", "July", "August", "September",
"October", "November", "December" };
month.setViewAdapter(new DateArrayAdapter(this, months, curMonth));
month.setCurrentItem(curMonth);
month.addChangingListener(listener);
// year
int curYear = calendar.get(Calendar.YEAR);
year.setViewAdapter(new DateNumericAdapter(this, curYear-10, curYear + 10,0));
year.setCurrentItem(curYear);
year.addChangingListener(listener);
// day
updateDays(year, month, day);
day.setCurrentItem(calendar.get(Calendar.DAY_OF_MONTH)-1);
}
public void setclick(View v) {
if(GlobalData.forwhich.equals("1"))
{
GlobalData.leave_date_from = String.valueOf(year.getCurrentItem()+2001) + "-"
+ month.getCurrentItem() + "-"
+ String.valueOf(day.getCurrentItem()+1);
}
else if(GlobalData.forwhich.equals("2"))
{
GlobalData.leave_date_to = String.valueOf(year.getCurrentItem()+2001) + "-"
+ month.getCurrentItem() + "-"
+ String.valueOf(day.getCurrentItem()+1);
}
else
{
GlobalData.selected_date = String.valueOf(year.getCurrentItem()+2001) + "-"
+ months[month.getCurrentItem()] + "-"
+ String.valueOf(day.getCurrentItem()+1);
}
finish();
}
/**
* Updates day wheel. Sets max days according to selected month and year
*/
void updateDays(WheelView year, WheelView month, WheelView day) {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR,calendar.get(Calendar.YEAR) + year.getCurrentItem());
calendar.set(Calendar.MONTH, month.getCurrentItem());
int maxDays = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
day.setViewAdapter(new DateNumericAdapter(this, 1, maxDays, calendar
.get(Calendar.DAY_OF_MONTH) - 1));
int curDay = Math.min(maxDays, day.getCurrentItem() + 1);
day.setCurrentItem(curDay - 1, true);
calendar.set(Calendar.DAY_OF_MONTH, day.getCurrentItem() + 1);
Log.i("date :",
new SimpleDateFormat("dd/MM/yyyy").format(calendar.getTime()));
}
/**
* Adapter for numeric wheels. Highlights the current value.
*/
private class DateNumericAdapter extends NumericWheelAdapter {
// Index of current item
int currentItem;
// Index of item to be highlighted
int currentValue;
/**
* Constructor
*/
public DateNumericAdapter(Context context, int minValue, int maxValue,
int current) {
super(context, minValue, maxValue);
this.currentValue = current;
setTextSize(16);
}
@Override
protected void configureTextView(TextView view) {
super.configureTextView(view);
if (currentItem == currentValue) {
view.setTextColor(0xFF0000F0);
}
view.setTypeface(Typeface.SANS_SERIF);
}
@Override
public View getItem(int index, View cachedView, ViewGroup parent) {
currentItem = index;
return super.getItem(index, cachedView, parent);
}
}
/**
* Adapter for string based wheel. Highlights the current value.
*/
private class DateArrayAdapter extends ArrayWheelAdapter<String> {
// Index of current item
int currentItem;
// Index of item to be highlighted
int currentValue;
/**
* Constructor
*/
public DateArrayAdapter(Context context, String[] items, int current) {
super(context, items);
this.currentValue = current;
setTextSize(16);
}
@Override
protected void configureTextView(TextView view) {
super.configureTextView(view);
if (currentItem == currentValue) {
view.setTextColor(0xFF0000F0);
}
view.setTypeface(Typeface.SANS_SERIF);
}
@Override
public View getItem(int index, View cachedView, ViewGroup parent) {
currentItem = index;
return super.getItem(index, cachedView, parent);
}
}
}
+0
が実際に携帯電話のギャップ権利関係していないことがわかり付属のいくつかのコードを持っていますか? –
+0
はいphongap – Google
2
ここでは、XMLファイル
<LinearLayout android:layout_height="wrap_content" android:layout_width="wrap_content"
android:layout_gravity="center_horizontal" android:paddingLeft="12dp"
android:paddingRight="12dp" android:paddingTop="30dp">
<com.wheel.WheelView android:id="@+id/day"
android:layout_height="wrap_content" android:layout_width="46dp" />
<com.wheel.WheelView android:id="@+id/month"
android:layout_height="wrap_content" android:layout_width="100dp" />
<com.wheel.WheelView android:id="@+id/year"
android:layout_height="wrap_content" android:layout_width="wrap_content" />
</LinearLayout>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Set"
android:onClick="setclick">
</Button>
関連する問題
- 1. 生年月日ウィザードプログラム
- 2. wordpress meta_query生年月日と誕生日
- 3. ドッグイヤー生年月日クエリ
- 4. 生年月日を表す
- 5. 日、月、年からNSDateを生成
- 6. 生年月日のCHECK制約?
- 7. 日付ピッカー - 月/年
- 8. ルビーのTime.new(年、月、日)とTime.local(年、月、日)の差
- 9. SASは年齢から生年月日を見つけます
- 10. Javascriptの生年月日 - 選択を防止する2月30日
- 11. 登録日
- 12. Nullableでの年月日
- 13. 日、月、年のPythonタイムスタンプ
- 14. Rubyの年月日は?
- 15. Coverting 2011年9月13日12時00分00秒AM 2011年9月13日
- 16. システム日付とスプリット日、月、年
- 17. 年月日の設定日時
- 18. バディ登録ページ
- 19. Facebookの登録日
- 20. 2012年2月7日火曜日に変換する日付2012年2月7日
- 21. 配列(= "月" によってas.Date( "2016年3月31日")、as.Date( "2016年6月30日"))
- 22. 生年月日を取得するLINQクエリ
- 23. テーブルに生年月日を追加する
- 24. 生年月日Ruby on Rails 3のUI要素
- 25. 生年月日の選択要素を選択
- 26. アンドロイドの血液型と生年月日の確認
- 27. PHPの生年月日を計算する
- 28. PHPの登録ページ
- 29. 日付を日/月/年(2012年1月20日)のPythonに変換するには
- 30. mySql:2000年1月1日から2000年1月1日に日付を変換
は、私はplzは – Google