當我運行該應用程序。按鈕拒絕迴應。我設置了一個Toast和一個logcat來檢查響應。但不是。請幫忙解決我的按鈕沒有在Android工作室響應
這是我的源代碼
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:id="@+id/textView" />
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView"
android:layout_centerHorizontal="true"
android:layout_marginTop="14dp"
android:id="@+id/button"
tools:onClick="topClick" />
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button"
android:layout_centerHorizontal="true"
android:layout_marginTop="14dp"
android:id="@+id/button2"
tools:onClick="bottomClick" />
和我的Java方法;
public class MyActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_layout);
//Testing the Toast and Log in action
Toast.makeText(this, "Can you see me?", Toast.LENGTH_SHORT).show();
Log.i("info", "Done creating the app");
}
//creating method topclick
public void topClick(View v) {
Toast.makeText(this, "Top button clicked", Toast.LENGTH_SHORT).show();
Log.i("info", "The user clicked the top button");
}
//creating method bottomclick
public void bottomClick(View v) {
Toast.makeText(this, "Bottom button clicked", Toast.LENGTH_SHORT).show();
Log.i("info", "the user clicked the bottom button");
}
}