如何创建按钮柜台? [英] How to create counter on button?
本文介绍了如何创建按钮柜台?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想这个按钮对按钮的右侧部分中心和0创建按钮文本=SomeText。其中,0是计数器,当我点击这个按钮反++递增,成为1... 我想知道如何配合textviev与按钮的右侧部分?
<按钮
机器人:ID =@ + ID /按钮1
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_centerHorizontal =真
机器人:layout_marginTop =85dp
机器人:背景=@可绘制/ button_menu
机器人:的onClick =but1_Count
机器人:文本=SomeText
机器人:文字颜色=@可绘制/ text_color
机器人:TEXTSIZE =100dp/>
解决方案
私有静态诠释柜台= 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); } });
这篇关于如何创建按钮柜台?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文