Android 小项目之SQLite 使用法门
2010-06-13 15:25:00 来源:WEB开发网myCursor.moveToPosition(arg2);
_id=myCursor.getInt(0);
myEditText.setText(myCursor.getString(1));
}
});
myListView.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
SQLiteCursor sc=(SQLiteCursor)arg0.getSelectedItem();
_id=sc.getInt(0);
myEditText.setText(sc.getString(1));
}
@Override
public void onNothingSelected(AdapterView arg0) {
// TODO Auto-generated method stub
}
});
}
private void operation(String cmd)
{
if(myEditText.getText().toString().equals(""))
return;
if(cmd=="add")
db.insert( myEditText.getText().toString());
if(cmd=="edit")
db.update(_id, myEditText.getText().toString());
if(cmd=="delete")
db.delete(_id);
myCursor.requery();
myListView.invalidateViews();
myEditText.setText("");
_id=0;
}
}
至此,功能己经基本完成。
源码下载:/Files/TerryBlog/testDb.rar
如果你什么疑问或者建议请:QQ:285735942 或 Email:terryyhl@gmail.com
更多精彩
赞助商链接