我有一个 24 小时格式的 timePicker,我想获取结果,将它们放入变量中,另外使用变量,然后在 textView 中显示它们。Eclipse 没有给我和语法错误,但是当我运行应用程序时,它在我启动“DisplayMessageActivity.java”时崩溃。
这是代码:
package com.example.sleepytime;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.TimePicker;
@SuppressLint("NewApi")
public class DisplayMessageActivity extends Activity {
TimePicker timepicker;
public int hour1 = timepicker.getCurrentHour();
public int min1 = timepicker.getCurrentMinute();
@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_message);
// Show the Up button in the action bar.
getActionBar().setDisplayHomeAsUpEnabled(true);
timepicker = (TimePicker) findViewById(R.id.timePicker1);
timepicker.setIs24HourView(true);
Button mButton = (Button) findViewById(R.id.button1);
mButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View printIt) {
final TextView mTextView = (TextView) findViewById(R.id.print);
mTextView.setText(hour1 + min1);
}
});
}
}