我想要將TextView內容更改爲線程中的計算結果,但執行時會崩潰。這是我的代碼。無法在runOnUiThread中更改UI
new Thread(new Runnable() {
public void run() {
while (i < 5) {
i++;
}
getActivity().runOnUiThread(new Runnable() {
public void run() {
TextView txv = (TextView) getView().findViewById(R.id.txvone);
Log.d("123","i = "+ i);
txv.setText(i);//CRASH!!!
}
});
}
}).start();