ハイ、
私は Android の開発に不慣れで、本を読んで慣れ親しんでいます。このコードは本にもありましたが、今のところ動作しません。コードは単純です。レイアウトは次のとおりです。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Hello"/>
<Button
android:id="@+id/trigger"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Press Me"/>
</LinearLayout>
Javaコードは次のとおりです。
private int buttonPress = 0;
TextView mButtonLabel;
private long mStartTime = 0L;
TextView mTimeLabel;
private Handler mHandler = new Handler();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if(mStartTime == 0L) {
mStartTime = SystemClock.uptimeMillis();
mHandler.removeCallbacks(mUpdateTimeTask);
mHandler.postDelayed(mUpdateTimeTask, 100);
}
mTimeLabel = (TextView)findViewById(R.id.text);
mButtonLabel = (TextView)findViewById(R.id.trigger);
Button startButton = (Button)findViewById(R.id.trigger);
startButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mButtonLabel.setText("Megnyomva: " + ++buttonPress + " alkalommal");
}
});
}
private Runnable mUpdateTimeTask = new Runnable() {
public void run() {
final long start = mStartTime;
long milis = SystemClock.uptimeMillis() - start;
int seconds = (int) (milis/1000);
int minutes = (seconds/60);
seconds = seconds % 60;
mTimeLabel.setText("" + minutes + ":" + String.format("%02d", seconds));
mHandler.postDelayed(this, 200);
}
};
@Override
protected void onPause() {
mHandler.removeCallbacks(mUpdateTimeTask);
super.onPause();
}
@Override
protected void onResume() {
super.onResume();
mHandler.postDelayed(mUpdateTimeTask, 100);
}
私の問題は、ボタンが何らかの形で表示されないことです。助言がありますか?
ありがとう、デイブ。