このメソッドは、Activity ではない RecordTable クラスで定義します。
メイン UI スレッドから呼び出し、有効な UI スレッド コンテキストをパラメーターとして渡します。
もちろん、次のメッセージでは機能しません。
java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
runOnUiThread
代わりに使用することをお勧めする他の投稿を見ましたnew thread
が、クラスはアクティビティrunOnUiThread
ではないため、利用できません。
runnable() の外でダイアログを開始しても機能しません。
誰かがこの問題を抱えていて、それを解決する方法を見つけましたか?
public synchronized void scrollUp(final Context context, final ArrayList<Record> list, final int count) {
new Thread(new Runnable() {
public void run() {
setScrolling(true);
ProgressDialog pd = ProgressDialog.show(context, "", context.getResources().getString(R.string.loading_msg), true);
int n = Math.max(mViewStartIndex - count, 0);
for(int i = mViewStartIndex - 1; i >= n; i--) {
RecordTable.this.addFirstRow(list.get(i));
RecordTable.this.removeViews(RecordTable.this.getChildCount() - 1, 1);
}
pd.dismiss();
setScrolling(false);
}
}).start();
}