正在尝试在将值附加到recyclerview时更新进度条。即使在创建新线程后,setProgress方法也无法正常工作。在这里附上我的代码
progress_horizontal.setVisibility(View.VISIBLE);
progress_horizontal.setProgress(0);
progress_horizontal.setMax(titles.length);
new Thread(new Runnable() {
public void run() {
handler.post(new Runnable() {
public void run() {
for (int i = 0; i < titles.length; i++) {
itemListsList.add(new ListItemRadioLists(titles[i], false));
progress_horizontal.setProgress(i);
}
rv_search.setAdapter(itemAdapter);
progress_horizontal.setVisibility(View.GONE);
}
});
}
}).start();
有人可以帮我解决这个问题吗?
您应使用Looper在线程中查看ui。
Looper.prepare();
progress_horizontal.setProgress(i);
Looper.loop();