activity点击跳转并传参数到fragment如何修改fragment中的控件为传递过来的参数

我自己写了一个方法来传递参数的,目的是要修改控件的值
activity 代码部分
dia=new DiagFragment();
nBtb=(Button)findViewById(R.id.bt);
nBtb.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

            dia.show(MainActivity.this.getSupportFragmentManager(), null);
        }
    });

    timer.schedule(task, 1000, 5000);
}

TimerTask task = new TimerTask() {
    public void run() {
        if (dia!=null){
            ((DiagFragment) dia).setData2(String.valueOf((Math.random() * 10)));

        }
    }
};


    Dialogfragment 部分
     public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view=inflater.inflate(R.layout.list_dialog,null);
    mContext=getActivity();

    initView(view);

    return view;
}

     public void initView(View view){
    tx1=(TextView)view.findViewById(R.id.tv_1);
     tx2=(TextView)view.findViewById(R.id.txv_2);

}


public void setData2(String string) {

    str2=string;
    Log.w(TAG, "setData2: "+string );
    tx2.setText(string);
}

    我能打印到定时器传过来的数据
    但只要我加上tx2.setText(string)就报错

setData2方法是在线程中执行的. ui的绘制不能在线程中执行.
tx2.setText(string);
写在写线程即可解决.
new Handler.post(new runable(){
***
tx2.setText(string);

}

或者使用activity.runonuithread

用 getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
tx2.setText(string);
}
});