我有以下片段类:
public class fragment1 extends Fragment {
private TextView bunz_count;
private TextView money_count;
private Bunz bunz;
private Handler handler;
int delay = 1000;
View view;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
bunz = Bunz.getInstance();
handler = new Handler();
view = inflater.inflate(R.layout.fragment1, container, false);
handler.postDelayed(new Runnable(){
public void run(){
update(view);
handler.postDelayed(this, delay);
}
}, delay);
return view;
}
public void update(View view){
bunz_count = (TextView) view.findViewById(R.id.final_bunz_count);
money_count = (TextView) view.findViewById(R.id.final_money_count);
//System.out.println(bunz.getBaker1());
//System.out.println(number);
bunz.setBunz(bunz.getBunz().add((number)));
bunz_count.setText("Bunz: " + bunz.getBunz());
money_count.setText("Money: " + bunz.getMoney());
System.out.println("bunz" + bunz.getBunz());
}
}
更新玩家货币的 UI 显示。但是,由于有许多不同的进程在后台运行,该线程会滞后并出现问题。我怎样才能在单独的线程上运行它来避免这种情况?
慕运维8079593
相关分类