執行代碼以更快的速度解析/加載內容形式json/db在AsyncTask中。我加載5000行,每行〜400個字符。沒有AsyncTask需要更長的時間。
private class YourTask extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... s) {
//Here you have to make the loading/parsing tasks
//Don't call any UI actions here. For example a Toast.show() this will couse Exceptions
// UI stuff you have to make in onPostExecute method
}
@Override
protected void onPreExecute() {
// This method will called during doInBackground is in process
// Here you can for example show a ProgressDialog
}
@Override
protected void onPostExecute(Long result) {
// onPostExecute is called when doInBackground finished
// Here you can for example fill your Listview with the content loaded in doInBackground method
}
}
要執行你只需要撥打:
new YourTask().execute("");
在這裏你可以瞭解更多關於AsyncTasks:
AsyncTask developer Guide
怎麼樣,你自己測試它? – ariefbayu
嘗試使用它與Json格式。 Android有Json支持。 –
我的猜測是項目2(數據庫)的延遲加載(您可以加載100個項目,在用戶滾動到列表結尾之前,您可以獲得更多的100並從適配器調用notifyDataSetChanged。但是,如果您的單詞列表始終是靜態的,則JSON文件可以是更有效的選擇,就像@MuratNafiz說的。 – dougcunha