Android Studio:在android:onClick属性的父级或祖先上下文中找不到方法handleSelection(View)

时间:2019-07-13 05:00:35

标签: android-studio

当我点击歌曲时,我的应用程序一直崩溃。而在logcat中,这就是问题所在。预先感谢。

could not find a method handleSelection(View) in a parent or ancestor Context for android:onClick attribute defined on view class android.support.v7.widget.AppCompatImageButton with id 'S1001'

Home.java

public void handleSelection(View view) {

    String resourceId = AppUtil.getResourceId(getContext(), view);
    Song selectedSong = songCollection.searchById(resourceId);

    AppUtil.popMessage(getContext(), "Streaming Song: " + selectedSong.getTitle());

    sendDataToActivity(selectedSong);
}

fragment_home.xml

<ImageButton
    android:id="@+id/S1001"
    android:layout_width="80dp"
    android:layout_height="80dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="52dp"
    android:layout_marginEnd="8dp"
    android:layout_marginBottom="8dp"
    android:onClick="handleSelection"
    android:scaleType="centerCrop"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.066"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.011"
    app:srcCompat="@drawable/michael_buble_collection" />

0 个答案:

没有答案