Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android seflmake工具栏中带有onClick的ImageButton_Android_Onclick_Crash_Android Toolbar_Android Imagebutton - Fatal编程技术网

Android seflmake工具栏中带有onClick的ImageButton

Android seflmake工具栏中带有onClick的ImageButton,android,onclick,crash,android-toolbar,android-imagebutton,Android,Onclick,Crash,Android Toolbar,Android Imagebutton,您好:)我想向工具栏中的ImageButton添加onClick方法 它使用onBackPressed()工作,但不是通过单击ImageButton。应用程序正在崩溃,但我无法从控制台读取错误消息,我还不知道如何正确调试它 你能帮我找出可能丢失的东西吗? 非常感谢:) toolbar\u room.xml <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"

您好:)我想向工具栏中的ImageButton添加onClick方法

它使用
onBackPressed()
工作,但不是通过单击ImageButton。应用程序正在崩溃,但我无法从控制台读取错误消息,我还不知道如何正确调试它

你能帮我找出可能丢失的东西吗? 非常感谢:)

toolbar\u room.xml

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar_room"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageButton
        android:layout_width="?attr/actionBarSize"
        android:layout_height="match_parent"
        android:background="@drawable/ic_back"
        android:id="@+id/btn_roomBack"
        android:onClick="backToMain"/>
</LinearLayout>
<android.support.v7.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="de.hftl.smartcast.RoomActivity"
android:orientation="vertical">

<include layout="@layout/toolbar_room"></include>
//Code
注意:我添加了
android:parentActivityName=“.RoomActivity”

到my AndroidManifest.xml。

您应该像下面这样将视图参数传递给函数,以便在单击xml时使用

public void backToMain(View v){

非常感谢。然后我必须将v提供给
AlertDialog.Builder alertDlg=new AlertDialog.Builder(v)?您不需要这样做。因为“构建器(this)”中的“this”用于上下文。
public void backToMain(View v){