更新时间:2023-12-01 17:11:58
私有静态诠释柜台= 0; button1.setOnClickListener(新OnClickListener(){ @覆盖 的onClick(视图v){ 计数器+ = 1 button.setText(一些文本+计数器); } });
I want to create button with text = "SomeText" on center of this button and "0" on right part of button. Where "0" is the Counter and when I click this button Counter++ increments, and becomes "1"... I would like to know how to tie textviev with "right part of button" ?
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="85dp"
android:background="@drawable/button_menu"
android:onClick="but1_Count"
android:text="SomeText"
android:textColor="@drawable/text_color"
android:textSize="100dp" />
private static int counter = 0; button1.setOnClickListener(new OnClickListener(){ @Override onClick(View v){ counter += 1 button.setText("Some text" + counter); } });