1
我試圖在我的分配時間與系統時間相同時運行我的方法。我確信這兩個日曆打印輸出結果相同,但它不運行該方法。分配時間與系統時間相同時的運行方法
public class Intake extends Fragment {
TextView tv1, tv2,tv3;
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState){
return inflater.inflate(R.layout.intake, container, false);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState){
tv1 = (TextView) getActivity().findViewById(R.id.tv1);
tv2 = (TextView) getActivity().findViewById(R.id.tv2);
tv3 = (TextView) getActivity().findViewById(R.id.tv3);
Calendar settime = Calendar.getInstance();
settime.set(Calendar.HOUR_OF_DAY, 10);
settime.set(Calendar.MINUTE,46);
settime.set(Calendar.SECOND,10);
Calendar systime = Calendar.getInstance();
systime.getTime();
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
String aa = String.valueOf((sdf.format(settime.getTime())));
String bb = String.valueOf((sdf.format(systime.getTime())));
tv1.setText(aa);
tv2.setText(bb);
if (aa == bb){
runMath();
}
}
}
感謝您
您的問題可能是你在創建視圖時,只檢查,而不是不斷。也有類似時間的事情,你不能指望精確匹配,並且應該與閾值或大於/小於閾值進行比較。 – StaticShadow