イベントへのカウントダウンクロックを表示するだけのこのコードがあります。通常の時計とは異なり、最後の秒の桁のジャンプに関して問題があります。これが私が使っているコードです。誰かがこの問題がどこにあるかについてのガイダンスを提供してもらえますか?敬具。
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new Timer().schedule(new TimerTask() {
File sdcard = Environment.getExternalStorageDirectory();
File cfgFile = new File(sdcard, "TimeTillParis/config.txt");
@Override
public void run() {
runOnUiThread(new Runnable() {
public void run() {
try {
InputStream is = new FileInputStream(cfgFile);
Properties prop = new Properties();
prop.load(is);
int mmY = Integer.parseInt(prop.getProperty("YEAR"));
int mmM = Integer.parseInt(prop.getProperty("MONTH"));
int mmD = Integer.parseInt(prop.getProperty("DAY"));
int mmH = Integer.parseInt(prop.getProperty("HOUR"));
int mmC = Integer.parseInt(prop.getProperty("MINUTE"));
int mmS = Integer.parseInt(prop.getProperty("SECOND"));
Calendar cal = Calendar.getInstance();
Date today = new Date(System.currentTimeMillis());
cal.set(Calendar.YEAR, mmY);
cal.set(Calendar.MONTH, mmM);
cal.set(Calendar.DAY_OF_MONTH, mmD);
cal.set(Calendar.HOUR_OF_DAY, mmH);
cal.set(Calendar.MINUTE, mmC);
cal.set(Calendar.SECOND, mmS);
long milliseconds = (cal.getTimeInMillis() - today.getTime());
String mD="", mH="", mM="", mS="", boxText="";
mD += (milliseconds / (1000*60*60*24));
mH += (milliseconds / (1000*60*60) % 24);
mM += (milliseconds / (1000*60) % 60);
mS += (milliseconds / 1000 % 60);
boxText += "Next visit to Paris in \n\n" +
mD + "d " +
mH + "h " +
mM + "m " +
mS + "s";
TextView textView = (TextView) findViewById(R.id.textView_date_display);
textView.setText(boxText);
} catch (FileNotFoundException e) {
String cfgNotFound="";
cfgNotFound += "config.txt not found!";
TextView textView = (TextView) findViewById(R.id.textView_date_display);
textView.setText(cfgNotFound);
//e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
}, 0, 100);
}
}