我有一個關於日期選擇器功能的問題。如何日期選擇器的值保存到SQLite數據庫
如何保存日期選擇器來SQLite數據庫的價值?
假設我創建一個按鈕來設置日期和一個按鈕來保存到數據庫...
main.java
public class main extends Activity implements OnClickListener {
private Calendar dateTime=Calendar.getInstance();
private SimpleDateFormat dateFormatter = new SimpleDateFormat("MMMM dd, yyyy");
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.addshoppinglist);
mSaveBttn = (Button) findViewById(R.id.saveBttn);
mSetDateBttn = (Button) findViewById(R.id.shoppingDate);
mCancelBttn = (Button) findViewById(R.id.cancelBttn);
mSaveBttn.setOnClickListener(this);
mSetDateBttn.setOnClickListener(this);
mCancelBttn.setOnClickListener(this);
helper = new ProductDatabaseHelper(this);
model = helper.getAll();
}
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.saveBttn:
break;
case R.id.cancelBttn:
Intent mainIntent = (new Intent(AddShoppingList.this, main.class));
startActivity(mainIntent);
break;
case R.id.shoppingDate:
showDialog(DIALOG_DATE);
}
}
protected Dialog onCreateDialog(int id){
switch(id){
case DIALOG_DATE:
return new DatePickerDialog(this,new OnDateSetListener(){
public void onDateSet(DatePicker view,int year,int monthOfYear,int dayOfMonth){
dateTime.set(year,monthOfYear,dayOfMonth);
mSetDateBttn.setText(dateFormatter
.format(dateTime.getTime()));
}
} ,dateTime.get(Calendar.YEAR),
dateTime.get(Calendar.MONTH),
dateTime.get(Calendar.DAY_OF_MONTH));
}
}
有誰知道如何保存日期格式的數據庫?
真的THX的幫助......感謝...... – jacky
隨時歡迎花花公子:) – Akshay