2

private void init()(
mEcName =(EditText)findViewByld(R.id.et name); mEtPhone #(EditText)findViewById(R.id.et phone); mTvShow=(TextView)findViewById(R.id.tv show); mBtnAdd=(Button) findViewById(R.id.btn add);
mBtnQuery=(Button) findViewById(R.id.btn query); mBtnUpdate *(Button) findViewById(R.id.btn update); mBtnDelete=(Button)findViewById(R.id.btn delete); mBtnAdd.setOnClickListener(this); mBtnQuery.setOnClickListener(this); mBtnUpdate.setOnClickListener(this); mBtnDelete.setOnClickListener(this);
@Override
public void onClick(View v)(
String name; String phone;
SQLiteDatabase db;
ContentValues values; switch(v.getId())(
case R.id.btn add://添加数据
name:=mEtName.getText()toString(); phone =mEtPhone.getText().toString();
dbmyHelper.getWritableDatabase();//获取可读写SQLiteDatabase 对象 values =new ContentValues(); //创建Contentvalues对象
values.put(“name”,name); //将数据添加到ContentValues对象
values.put(“phone”,phone);
db.insert(“information”, null, values);
Toast.makeText(this,“信息已添加”,Toast.LENGTH_SHORT).show(); db.close(); break;
case R.id.btn_query://查询数据
db=myHelper.getReadableDatabase();
Cursor cursor =db.query(“information”, null, null, null, null
null,null);
if (cursor.getCount() ==0){
mTvShow.setText("");
Toast.makeText(this,“没有数据”,Toast.LENGTH SHORT).show();} else {
cursor.moveToFirst();
mTvShow.setText(“Name :”+cursor.getString(1)+
;Tel:"+ cursor.getString(2));
while (cursor.moveToNext())【
mTvShow.append("\n"+“Name:”+cursor.getString(l)+
" :Tel :"+cursor.getString(2));
cursor.close(); db.close(); break;

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值