【发布时间】:2013-01-12 07:16:20
【问题描述】:
我阅读了一些需要将我的 runOnUiThread 转换为 AsyncTask 的链接: Android: RunOnUiThread vs AsyncTask
但我无法完成它。我正在实现一个从数据库中获取查询的 AutoCompleteText。
我的 runOnUiThread 和新线程(它编译):
new Thread(new Runnable() {
public void run() {
final DataBaseHelper dbHelper = new DataBaseHelper(ActivityName.this);
dbHelper.openDataBase();
item_list = dbHelper.getAllItemNames();
ActivityName.this.runOnUiThread(new Runnable() {
public void run() {
ArrayAdapter<String> sAdapter = new ArrayAdapter<String>(
ActivityName.this,
android.R.layout.simple_dropdown_item_1line,
item_list);
itemNameAct = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView_item_name);
itemNameAct.setAdapter(sAdapter);
}
});
}
}).start();
我将工作线程部分放在 doInBackground 中,将代码的 runOnUiThread 部分放在 onPostExecute 中,但它在启动时崩溃。
【问题讨论】:
-
哦!解决了!我正在扩展 AsyncTask
-
稍后当我被允许访问自我答案时,我将发布课程。
标签: android multithreading android-asynctask autocompletetextview