这个程序的主要动机是在Android ListView中显示一些来自SQLite的数据。HashMap只给我最后一个数据
protected String doInBackground(String... args) {
SQLiteOpenHelper helper = new Dictionary(contex);
SQLiteDatabase db = helper.getReadableDatabase();
EditText et = (EditText) findViewById(R.id.search);
String word = et.getText().toString();
wordlist = new ArrayList<>();
String query = "SELECT ID, WORD" +
" FROM E_DICT WHERE WORD LIKE '"+word+"%' ORDER BY WORD ASC LIMIT 100 ";
Cursor cursor = db.rawQuery(query, null);
if(cursor!=null){
if(cursor.moveToFirst()){
do{
long a = cursor.getLong(0);
String b = cursor.getString(1);
HashMap<String, String> map = new HashMap<String, String>();
map.put(EDICT_WORD, b);
map.put(EDICT_ID, ""+a);
Log.d("RESULT", a +" " + b); //Till this this like everything seems to be ok.
wordlist.add(map);
}
while(cursor.moveToNext());
}}
return null;
}
现在我加载我的数据在某些AsyncTask<String, String, String>
这样的:
protected void onPostExecute(String file_url) {
pDialog.dismiss();
runOnUiThread(new Runnable() {
public void run() {
ListAdapter adapter = new SimpleAdapter(
Main.this, wordlist, R.layout.word_list,
new String[] {EDICT_WORD, EDICT_ID},
new int[] {R.id.eDict_Word, R.id.eDict_Id});
setListAdapter(adapter);
}
});
}
这给了我最后EDICT_ID
只列表视图输出。我在哪里做错了?
您的数据库中有多少数据?而且,wordlist有多少项? –