【Mac・Android Studio】ストップウォッチを作ってみる その3(失敗編)

Android Studio
スポンサーリンク

こんにちは。

ストップウォッチ作成の3回目になります。

前回は、以下のような警告がでたととこで終了しています。

Missing accessibility label: provide either a view with an android:labelFor that references this view or provide an android:hint Editable text fields should provide an android:hint or, provided your minSdkVersion is at least 17, they may be referenced by a view with a android:labelFor attribute. When using android:labelFor, be sure to provide an android:text or an android:contentDescription. If your view is labeled but by a label in a different layout which includes this one, just suppress this warning from lint.

えーっと、よくわかりませんが、android:labelForが足りないという
ことでしょうか💦

activity_main.xmlに足してみましょう。

<EditText
android:id=”@+id/editText”
style=”@style/Widget.AppCompat.AutoCompleteTextView”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:ems=”10″
android:inputType=”time”
android:labelfor=”0.0″
android:text=”@string/_0″
・・・・・/>

8行目に追加したandroid:labelforの値は念のため数字をセットしています。
だが・・・。
それでも、警告は消えず・・・。
うーん、、、java側の処理を記述すれば消える系の警告かなぁ。
この警告は一旦置いておいて、ちょっと先に進めてみようと思います。

では、javaクラスを作成していきましょう。

いつものように、MainActivity.javaに作成していきます😁
まずはメンバ変数です。

// 画面
EditText text;
// スタートボタン
Button staBtn;
// ストップボタン
Button stoBtn;
// 再開ボタン
Button restBtn;
// リセットボタン
Button reseBtn;

必要な画面テキストとボタンの変数を定義しています。

次にonCreate関数の処理です。
それぞれの画面上の情報を取得し、
ボタンが押された時の処理を記述していきます。
↓のコードは、まずスタートボタンが押された時の処理を書いています。

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

// 画面のテキスト情報を取得
text = findViewById(R.id.editText);
// スタートボタン情報を取得
staBtn = findViewById(R.id.button);
// ストップボタン情報を取得
stoBtn = findViewById(R.id.button2);
// 再開ボタン情報を取得
restBtn = findViewById(R.id.button3);
// リセットボタン情報を取得
reseBtn = findViewById(R.id.button4);

// スタートボタンが押下された時の処理
staBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick (View view) {
// 時間をカウントする処理を呼び出す。
}
});
}

では、スタートボタンが押された時に呼ばれる時間カウントの処理を
書こう!
・・・と思ったら、問題が発生しました😅

↓ ちょっとエミュレータで見てみようと思ったら、エラーが出ました☄

Cannot resolve symbol ‘R’ ・・・?
シンボルRが解決できないとな!
R.javaクラスのエラーですね💧
ここは、プロジェクト作成したらデフォルトで作成されるので、
本来エラーが出る場所ではないと思うのですが。。。
余計なコードをうっかり消してしまったのだろうか💦

・・・ちょっと一気にコードを進め過ぎたかな。
もうちょっとゆっくり処理を理解しながら進めていきたいと思います。

今日はここまで🤚

では、また次回。

コメント

タイトルとURLをコピーしました