你好,我新來的android的發展我米發展中國家需要獲得來自timePicker小時和分鐘的應用程序,所以我也這樣得到它:如何從虛空中的Android
public class MainActivity extends Activity {
TimePicker timePicker;
int hour, changedHour;
int minute, changedMinute;
TextView tv, tv1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv = (TextView) findViewById(R.id.textView1);
tv1 = (TextView) findViewById(R.id.textView2);
timePicker = (TimePicker) findViewById(R.id.timePicker1);
setCurrentTime();
timePicker.setOnTimeChangedListener(new OnTimeChangedListener() {
@Override
public void onTimeChanged(TimePicker arg0, int hourOfDay,
int minuteOf) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "Time set!",
Toast.LENGTH_SHORT).show();
changedHour = hourOfDay;
changedMinute = minuteOf;
tv.setText("Hour of Day is " + changedHour + " and Minute is "
+ changedMinute);
}
});
tv1.setText("Hour of Day is " + changedHour + " and Minute is "
+ changedMinute);
}
public void setCurrentTime() {
// TODO Auto-generated method stub
final Calendar c = Calendar.getInstance();
hour = c.get(Calendar.HOUR_OF_DAY);
minute = c.get(Calendar.MINUTE);
timePicker.setCurrentHour(hour);
timePicker.setCurrentMinute(minute);
}`
問題就在這裏
changedHour = hourOfDay;
changedMinute = minuteOf;
tv.setText("Hour of Day is " + changedHour + " and Minute is "
+ changedMinute);
我得到了改變的時候,我把它像小時將是hourOfDay = changedHour
,當我想要使用變量的方法之外同樣是分現在的問題是其設置爲0 HERE
tv1.setText("Hour of Day is " + changedHour + " and Minute is "
+ changedMinute);
請幫幫我!
測試它希望你的方法作品和感謝好解釋! –
都能跟得上你的代碼做什麼,它是設置當前時間changedHour我想要的應用設置改變時changedHour並通過changedHour在虛空方法setCurrentTime使用的方式是工作的罰款,而不是在onChangedTimeListener o.O –