I define this method in a RecordTable class, which is not an Activity.
I call it from the main UI thread and pass a valid UI thread context as parameter.
Of course, it does not work with the message:
java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
I saw in other post they recommend using runOnUiThread
instead of new thread
but since the class is not an activity runOnUiThread
is not available.
Starting the Dialog outside the runnable() does not work either.
Has anyone got this problem and found how to solve it?
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();
}