AndroidSQLite数据库创建和使用实战(一)(三)

2014-11-24 10:16:05 · 作者: · 浏览: 2
mGetAllBtn.setOnClickListener(getAllBtnClickListener); mDbAdapter = new DbAdapter(mContext); mDbAdapter.openDbase(); } OnClickListener addBtnClickListener = new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub PersonInfo tempPerson = new PersonInfo(); tempPerson.name = mNameEdTxt.getText().toString(); tempPerson.age = mAgeEdTxt.getText().toString(); tempPerson.sex = mSexEdTxt.getText().toString(); if ((mNameEdTxt.getText()!=null)&&(mAgeEdTxt.getText()!=null)&&(mSexEdTxt.getText()!=null)) { if (mDbAdapter.insertPersonInfo(tempPerson) >= 0) { Toast.makeText(mContext, "Add data to dbase successfull!", Toast.LENGTH_LONG).show(); } } else { Toast.makeText(mContext, "Please resure your input data is full ok ", Toast.LENGTH_LONG).show(); } } }; OnClickListener removeBtnClickListener = new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub if (mRmIdEdTxt.getText()!=null) { if (mDbAdapter.deletePersonInfo(Integer.parseInt(mRmIdEdTxt.getText().toString())) == true) { Toast.makeText(mContext, "Remove data from dbase successfull!", Toast.LENGTH_LONG).show(); } else { Toast.makeText(mContext, "Remove data from dbase failed!", Toast.LENGTH_LONG).show(); } } else { Toast.makeText(mContext, "Please resure your input id is full ok ", Toast.LENGTH_LONG).show(); } } }; OnClickListener getO
neBtnClickListener = new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub if (mPersonIdEdTxt.getText()!=null) { int idInPut = Integer.parseInt(mPersonIdEdTxt.getText().toString()); Cursor cursor = mDbAdapter.getPersonInfo(idInPut); if (cursor.moveToFirst() == true) { PersonInfo personInfo = new PersonInfo(); String id = cursor.getString(cursor.getColumnIndex(DbAdapter.KEY_ID)); personInfo.name = cursor.getString(cursor.getColumnIndex(DbAdapter.KEY_NAME)); personInfo.age = cursor.getString(cursor.getColumnIndex(DbAdapter.KEY_AGE)); personInfo.sex = cursor.getString(cursor.getColumnIndex(DbAdapter.KEY_SEX)); cursor.close(); String str = "No:"+id+",name:"+personInfo.name+",age:"+personInfo.age+",sex:"+personInfo.sex; mOneText.setText(str); } else { Toast.makeText(mContext, "Get One data from dbase failed!", Toast.LENGTH_LONG).show(); } } else { Toast.makeText(mContext, "Please resure your input id is full ok ", Toast.LENGTH_LONG).show(); } } }; OnClickListener upBtnClickListener = new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub PersonInfo tempPerson = new PersonInfo(); tempPerson.name = mNameUpEdTxt.getText().toString(); tempPerson.age = mAgeUpEdTxt.getText().toString(); tempPerson.sex = mSexUpEdTxt.getText().toString(); if (mDbAdapter.updatePersonInfo(Integer.parseInt(mIdUpEdTxt.g