Hatena::Groupandroid

組み込みプログラマのAndroid開発覚書

[Ruby] [Android入門] [Android 開発入門] [Android 開発チュートリアル] [逆引きAndroid] [Ruby] [Xperia] [チームらくらく]

2013-08-29

クロノメーターを使う

Android studio0.2.5使用

src/main/java/(中略)/MainActivity

package com.example.chronometersample12;

import android.os.Bundle;
import android.app.Activity;
import android.widget.Chronometer;

import com.example.chronometersample12.R.id;


public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Chronometer chronometer = (Chronometer) findViewById(id.chronometer);
        chronometer.setFormat("This is a Chronometer %s");
        chronometer.start();
    }

}

src/main/res/layout/activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context=".MainActivity">

    <Chronometer
        android:id="@+id/chronometer"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

</RelativeLayout>