我有一个FragmentActivity,附有3个片段。这3个片段有一个天文台,我希望它们在它们之间共享相同的时间......
有人能告诉我如何做我想做的事吗?
片段1
public class Run1Fragment extends Fragment {
private Chronometer chronometer;
private WearRunActivity runActivity;
private Run2Fragment run2;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.layout_run1, container, false);
chronometer = (Chronometer) view.findViewById(R.id.chronometer);
runActivity = new WearRunActivity();
chronometer.setOnChronometerTickListener(runActivity);
chronometer.start();
return view;
}
片段2
public class Run2Fragment extends Fragment {
private Chronometer r2Chronometer;
Run1Fragment run1;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.layout_run2, container, false);
r2Chronometer = (Chronometer) view.findViewById(R.id.chronometer);
/*r2Chronometer.setBase(run1.getChronometer().getBase());
r2Chronometer.start();*/
return view;
}
FragronActivity onChronometerTick监听器
@Override
public void onChronometerTick(Chronometer chronometer) {
System.out.println("CRONOMETROOOO");
this.chronometer.setBase(chronometer.getBase());
}
答案 0 :(得分:0)
好的,我找到了解决方案!
我没有为所有片段创建计时器,而是将其集成到片段活动片段中,因此只有我想要更改的文本才会被放置在其他片段中。