我是Android的初学者。我正在制作一个笑话API应用程序,每个按钮都是类别。所以我需要获取按钮的文本内容。这是我的xml代码。我看了很多线程,但是都在java中
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/button2"
android:layout_marginTop="20dp"
android:text="science"
android:onClick="getJoke"
/>
fun getJoke(v:View) {
val b = v as Button
val buttonText = b.getText().toString()
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句