我應該如何調用這個方法有字符串作爲參數或我應該如何執行這個查詢?如何在SQLite中創建where子句查詢?
代碼:
public class Samsung extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_samsung);
Intent intent = getIntent();
ArrayList<HashMap<String, String>> SamsungList = getSamsungInfo(null);
ListAdapter adapter = new SimpleAdapter(Samsung.this, SamsungList, R.layout.samsung_list, new String[] {Sqlite.COLUMN_MNAME, Sqlite.COLUMN_MMODEL,
Sqlite.COLUMN_MPRICE,Sqlite.COLUMN_MCAMERA} , new int[] {R.id.nameofsamsung, R.id.modelofsamsung, R.id.priceofsamsung, R.id.cameraofsamsung});
setListAdapter(adapter);
}
public ArrayList <HashMap<String, String>> getSamsungInfo(String samsung) {
ArrayList <HashMap<String, String>> wordList;
wordList= new ArrayList <HashMap<String, String>>();
Sqlite sqlll = new Sqlite(this);
SQLiteDatabase database = sqlll.getReadableDatabase();
String selectQuery = "SELECT * FROM mobile WHERE mname="+samsung+"'";
Cursor cursor = database.rawQuery(selectQuery, null);
if (cursor.moveToFirst()) {
do {
HashMap<String, String> map = new HashMap<String, String>();
map.put(Sqlite.COLUMN_MNAME, cursor.getString(0));
map.put(Sqlite.COLUMN_MMODEL, cursor.getString(1));
map.put(Sqlite.COLUMN_MPRICE, cursor.getString(2));
map.put(Sqlite.COLUMN_MCAMERA, cursor.getString(3));
wordList. add(map);
} while (cursor.moveToNext());
}
return wordList ;
}
}
這是給我的錯誤,沒有名爲「空」一欄。那麼調用方法時我應該怎樣傳遞。它並不是將三星作爲手機的mname欄中的插入值。
這是不允許的。要求我創建語言環境變量「samsung」。如果我將創建,它將是空的ified。 – apurva
這是一個方法參數,請參閱'getSamsungInfo(String samsung)' - 您需要更改調用該方法的部分,使用'getSamsungInfo(null)' – laalto
調用方法:而不是getSamsungInfo(null),我做什麼sholud? ?它不採取任何其他... – apurva