所以我试图做的是使用带有和onClick的ImageButton打开android侧菜单,但我一直收到错误。
home.xml (带有onClick的ImageButton所在位置)
<ImageButton
android:id="@+id/imgViewRefresh4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:visibility="gone"
android:onClick="click1"
style="?android:attr/borderlessButtonStyle"
android:src="@drawable/slide4" />
MainActivity.java (调用onClick的地方)
public void click1(){
mDrawerLayout.openDrawer(mDrawerList);
}
Logcat错误
12-13 21:38:01.276 3949-3949/com.projects.quickyAB E/AndroidRuntime: FATAL EXCEPTION: main
12-13 21:38:01.276 3949-3949/com.projects.quickyAB E/AndroidRuntime: java.lang.IllegalStateException: Could not find a method click1(View) in the activity class com.projects.quickyAB.MainActivity for onClick handler on view class android.widget.ImageButton with id 'imgViewRefresh4'
12-13 21:38:01.276 3949-3949/com.projects.quickyAB E/AndroidRuntime: at android.view.View$1.onClick(View.java:3825)
12-13 21:38:01.276 3949-3949/com.projects.quickyAB E/AndroidRuntime: at android.view.View.performClick(View.java:4475)
12-13 21:38:01.276 3949-3949/com.projects.quickyAB E/AndroidRuntime: at android.view.View$PerformClick.run(View.java:18796)
12-13 21:38:01.276 3949-3949/com.projects.quickyAB E/AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:730)
12-13 21:38:01.276 3949-3949/com.projects.quickyAB E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:92)
12-13 21:38:01.276 3949-3949/com.projects.quickyAB E/AndroidRuntime: at android.os.Looper.loop(Looper.java:137)
12-13 21:38:01.276 3949-3949/com.projects.quickyAB E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5455)
答案 0 :(得分:3)
您必须更改此方法以处理点击
public void click1(View v){
mDrawerLayout.openDrawer(mDrawerList);
}