私はAndroidアプリを書くのは初心者です。
ボタンの宣言に関する以下の2つの例は、すべてAndroid開発者サイトからのものです。(したがって、両方とも正しく機能している必要があります。)
例1:http ://developer.android.com/training/basics/firstapp/building-ui.htmlから
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_send"
android:onClick="sendMessage" />
例2:http ://developer.android.com/guide/topics/ui/declaring-layout.html#attributesから
<--! (In xml file) Define a view/widget in the layout file and assign it a unique ID: -->
<Button android:id="@+id/my_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/my_button_text"/>
//(In java file) Then create an instance of the view object and capture it from the layout (typically in the onCreate() method):
Button myButton = (Button) findViewById(R.id.my_button);
1)では、ボタンに「Android:id」を割り当てるのはいつですか?
2)xmlファイルのボタンに「Android:id」を割り当てたが、「MainActivity.java」の「onCreate()」でボタンを宣言しなかった場合はどうなりますか?