Java Android SQLite getContact问题
嘿,伙计们,我已经完成了这个教程: 并发现它非常有用,但他没有讨论如何使用“db.getContact()” 以下是处理程序中用于调用它的代码:Java Android SQLite getContact问题,java,android,sqlite,Java,Android,Sqlite,嘿,伙计们,我已经完成了这个教程: 并发现它非常有用,但他没有讨论如何使用“db.getContact()” 以下是处理程序中用于调用它的代码: // Getting single contact Contact getContact(int id) { SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.query(TABLE_CONTACTS, new String[] { KEY_ID,
// Getting single contact
Contact getContact(int id) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(TABLE_CONTACTS, new String[] { KEY_ID,
KEY_NAME }, KEY_ID + "=?",
new String[] { String.valueOf(id) }, null, null, null, null);
if (cursor != null)
cursor.moveToFirst();
Contact contact = new Contact(Integer.parseInt(cursor.getString(0)),
cursor.getString(1));
// return contact
return contact;
}
我试着通过以下方式来称呼它:
callButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EditText editText = (EditText)findViewById(R.id.editText2);
int id = Integer.parseInt(editText.getText().toString());
String name = db.getContact(id);
//do something
}
}
});
调用和返回所需内容的正确语法是什么?我尝试了很多不同的方法,但不理解。谢谢
Contact cn = db.getContact(id);