Ich lerne kotlin, und jetzt für mich nicht cearly ein Moment. Ich habe xmlKotlin in xml onClick funktioniert nicht
<ImageView
android:id="@+id/aries"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:tag="1"
android:onClick="clickItemHoro"
android:src="@drawable/aries" />
und Fragment
class ChooseYourHoroscope : Fragment(){
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
val view = inflater.inflate(R.layout.fragment_welcome_old, container, false)
return view;
}
fun clickItemHoro(v: View?){
Log.e("clickItemHoro", v!!.tag.toString())
}
}
wenn i-Taste klicken Ich habe Fehler:
Could not find method clickItemHoro(View) in a parent or ancestor Context for android:onClick attribute defined on view class android.support.v7.widget.AppCompatImageView with id 'aries'
warum es passiert? Code variieren einfach, aber es funktioniert nicht, ich kann nicht verstehen, warum
* Kotlin in xml onClick nicht funktioniert * ... es in Java nicht funktionieren würde, auch ... * in einem Elternteil oder einen Vorfahren Context * ... ist Fragment eines Context? – Selvin
ich verstand, Panzer! – g71132
[http://stackoverflow.com/questions/14139774/android-app-crashing-fragment-and-xml-onclick](http://stackoverflow.com/questions/14139774/android-app-crashing-fragment-and -xml-onclick) ref diese Verbindung sagte. – Jacob