-1
當我點擊一個按鈕時,我的屏幕加載速度很慢(因爲下載圖像?圖像文件雖然很小),所以我嘗試使用AsyncTask來幫助。該程序的工作原理,但我把圖片加載到一個AsyncTask,看看它會加載更快,每次崩潰的應用程序。我猜它與我設置的方式有關。我將如何解決它?使用可運行線程會更好嗎?謝謝!如何在我的AsyncTask中設置我的doInBackground參數?
類:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// no title
requestWindowFeature(Window.FEATURE_NO_TITLE);
// set full screen
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
// inflate listview
setContentView(R.layout.gmg);
**new Load.execute(); // executes AsyncTask**
...
gmgListView = (ListView) findViewById(R.id.gmg_list2);
GMGListViewAdapter adapter = new GMGListViewAdapter(this,
R.layout.gmg_list_row, rowItems);
gmgListView.setAdapter(adapter);
gmgListView.setOnItemClickListener(this);
}
的的AsyncTask:
private class Load extends AsyncTask<String, Void, Void> {
private ProgressDialog Dialog = new ProgressDialog(GMGListViewActivity.this);
@Override
protected void onPreExecute() {
Dialog.setMessage("Doing something...");
Dialog.show();
}
@Override
protected Void doInBackground(String... params) {
SparseArray<Spanned> gmgText = null;
Integer[] right = null;
SparseArray<Drawable> appIcon = null;
try {
gmgText = ParseContent.queryGMGText();
right = ParseContent.queryGMGRight();
appIcon = ParseContent.queryDrawable();
} catch (ParseException e) {
e.printStackTrace();
}
// Inflate GMG's rows
rowItems = new ArrayList<GMGRowItem>();
for (int i = 0; i < gmgText.size(); i++) {
GMGRowItem item = new GMGRowItem(appIcon.get(i), gmgText.get(i), right[i]);
rowItems.add(item);
}
return null;
}
protected void onPostExecute(Void unused) {
Dialog.dismiss();
}
}
可否請您將logcat與行號一起發佈,以便我們知道墜機原因? –
你的錯誤是什麼? – Kunu
add rowItems.add(item);在onPostMethod doinBackground不添加找你行onPOST等添加這個() –