我是一名android初學者。我試圖設計這個簡單的應用程序,該應用程序使用editText View從用戶處取得城市的名稱,並將其與數據庫中的相比較,然後返回該城市的郵政編碼。 現在,我遇到了遊標執行的問題。請幫助。如何查詢數據庫以獲取相應的代碼。如何在遊戲中使用遊標搜索數據庫(sqlite查詢)android
EditText city;
Button add,show1;
RadioGroup choose;
String k;
@Override
public void onCreate(Bundle savedInstanceState) {
try
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//final ContentValues values = new ContentValues();
city=(EditText)findViewById(R.id.editText1);
add=(Button)findViewById(R.id.add);
choose=(RadioGroup)findViewById(R.id.radio01);
show1=(Button)findViewById(R.id.button1);
k=city.getText().toString();
createDatabase();
}
catch(Exception e)
{
}
show1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
db=openOrCreateDatabase(DATABASE_NAME,Context.MODE_PRIVATE,null);
try{
if(k == "CITY")
{
String[] result_columns=new String[]{"_id","CITY","CODE"};
Cursor cursor = db.query(TABLE_NAME, result_columns,
"CITY" +"=?", new String[]{"k"}, null, null, null);
cursor.moveToFirst();
String xnewcode=cursor.getString(0);
Toast.makeText(activity1.this, xnewcode, Toast.LENGTH_LONG).show();
cursor.moveToNext();
//db.close();
}}
catch(Exception e)
{
Toast.makeText(activity1.this,"Fault in showing " + e,Toast.LENGTH_LONG).show();
}
}
});
具體來說,你有什麼麻煩? – 2011-06-02 13:21:33
http://stackoverflow.com/questions/6218395/android-app-which-retrieves-the-zip-code-for-each-city我遇到了整個程序的問題。 http://stackoverflow.com/questions/6218395/android-app-which-retrieves-the-zip-code-for-each-city – mohit 2011-06-02 18:06:35