我对日期选择器功能有疑问。
如何将 datepicker 的值保存到 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));
}
}
有谁知道如何将日期格式保存到数据库?