【发布时间】:2011-07-06 21:25:59
【问题描述】:
我有一个大约 1k 行的表格要显示。这个任务显然阻塞了 UI 线程,导致在 onCreate() 建表时出现黑屏。
我已经通过使用 AsyncTask 解决了这个问题,它在“doInBackground”函数中构建想要的 TableLayout 并将其显示在“onPostExecute”函数中。
问题 #1: 有什么我不熟悉的更好的做法吗?
问题 #2: 我的(简化的)“doInBackground”函数如下所示:
protected Void doInBackground(Void... v) {
tmpTableLayout = populateTable("");
return null;
}
我的(简化的)“onPostExecute”函数如下所示:
protected void onPostExecute(Void v) {
TableLayout ct = (TableLayout)findViewById(R.id.RealTable);
ct.removeAllViews();
/* WHATS HERE? */
}
我应该写什么而不是“这里有什么?”在最后一行代码中为了在“ct”中显示“tmpTableLayout”的内容?
提前致谢!
【问题讨论】:
-
数据从何而来?
-
它在应用程序初始化时来自网络并存储在全局变量中。
-
如果您将数据放入 sqlite 数据库,那么我的答案可能是最好的方法,否则,David Olsson 的答案将是要走的路。
标签: android android-asynctask tablelayout