真的需要一些帮助,我有 3 个 editText,我需要从 hh:mm:ss 中的两个中获取输入。然后使用数组和for循环找出差异,并在第三个editText中设置为文本。任何输入都会很棒!
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
end = (EditText) findViewById(R.id.etEnd);
start = (EditText) findViewById(R.id.etStart);
diff = (EditText) findViewById(R.id.etDiff);
calc = (Button) findViewById(R.id.bCalc);
clear = (Button) findViewById(R.id.bClear);
calc.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
int h1 = s[0];
int m1 = s[1];
int s1 = s[2];
int h2 = e[0];
int m2 = e[1];
int s2 = e[2];
String sGet2 = end.getText().toString(); // end to string
String sGet1 = start.getText().toString(); // start to string
String[] erA = sGet2.split(":"); // end string to end array
String[] srA = sGet1.split(":"); // start string to string array
for (int i = 0; i < srA.length; i++) {
inted = Integer.parseInt(erA[i].trim());
intst = Integer.parseInt(srA[i].trim());
s[i] = intst;
e[i] = inted;
}
if (s2 > s1) {m1--;s1 += 60;}
if (m2 > m1) {h1--;m1 += 60;}
int H, M, S;
S = s1 - s2;
M = m1 - m2;
H = h1 = h2;
diff.setText(H + ":" + M + ":" + S);
}
});
}
}
*另外,如果我以 1:2:3 作为开始时间和 4:5:6 作为结束时间运行它。它只吐出 (6) 结束时间的最后一位数字。如果我将结束时间设置为 3:4:5,它将在 editText 中显示 5。