public class DatabaseHelper extends SQLiteOpenHelper { public DatabaseHelper(Context context) { super(context,"account_daily", null, 1); } @Override public void onCreate(SQLiteDatabase db) { db.execSQL("create table if not exists account_cost(" + "id integer primary key, " + "cost_title varchar, " + "cost_date varchar, " + "cost_money varchar)"); }
fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); LayoutInflater inflater = LayoutInflater.from(MainActivity.this); View viewDialog = inflater.inflate(R.layout.new_cost_data, null); final EditText title = (EditText) viewDialog.findViewById(R.id.et_cost_title); final EditText money = (EditText) viewDialog.findViewById(R.id.et_cost_money); final DatePicker date = (DatePicker) viewDialog.findViewById(R.id.dp_cost_date); builder.setView(viewDialog); builder.setTitle("New Cost"); builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { CostBean costBean = new CostBean(); costBean.costTitle = title.getText().toString(); costBean.costMoney = money.getText().toString(); costBean.costDate = date.getYear() + "-" +(date.getMonth() + 1) + "-" + date.getDayOfMonth(); mDatabaseHelper.insertCost(costBean); mCostBeanList.add(costBean); mAdapter.notifyDataSetChanged(); } }); builder.setNegativeButton("Cancel",null); builder.create().show(); } }); }