安卓点击加减号实现数字加减功能
2017-12-19 17:31
246 查看
直接上代码
layout代码:
class代码:
效果图
layout代码:
<LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent"> <RelativeLayout android:onClick="iv_1" android:layout_gravity="center" android:layout_weight="4" android:layout_width="0dp" android:layout_height="match_parent"> <ImageView android:layout_centerInParent="true" android:src="@drawable/p2" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </RelativeLayout> <RelativeLayout android:layout_gravity="center" android:layout_weight="5" android:layout_width="0dp" android:layout_height="match_parent"> <TextView android:id="@+id/textView1" android:paddingTop="1dp" android:paddingBottom="1dp" android:gravity="center" android:layout_centerInParent="true" android:text="1" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </Relat 9e46 iveLayout> <RelativeLayout android:onClick="iv_2" android:layout_gravity="center" android:layout_weight="4" android:layout_width="0dp" android:layout_height="match_parent"> <ImageView android:layout_centerInParent="true" android:src="@drawable/p1" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </RelativeLayout> </LinearLayout>
class代码:
public void iv_1(View view){ textView1=(TextView)findViewById(R.id.textView1); num1=Integer.parseInt(textView1.getText().toString()); if(num1>1){ num1-=1; } textView1.setText(Integer.toString(num1)); } public void iv_2(View view){ textView1=(TextView)findViewById(R.id.textView1); num1=Integer.parseInt(textView1.getText().toString()); if(num1<999){ num1+=1; } textView1.setText(Integer.toString(num1)); }
效果图
相关文章推荐
- Android订票系统订票功能实现(特效点击按钮实现票数自动加减1)
- Unity实现类似于安卓原生项目的点击安卓返回按钮回到前一页的功能
- 实现点击加减数字进行变化
- 安卓实现类似连续点击5次进入开发者模式的功能
- 自定义view实现数字点击变换功能
- Unity实现相似于安卓原生项目的点击安卓返回button回到前一页的功能
- Axure 实现数字自动加键功能(点击“+”数字加1,点击“-”数字减1)
- [转]EasyPusher实现安卓Android手机直播推送同步录像功能(源码解析)
- 基于用户点击行为的数字图书搜索系统研究与实现 - 中国优秀硕士学位论文全文数据库
- [置顶] 安卓手机连接蓝牙打印机实现打印功能
- 点击tr实现选择checkbox功能,点击checkobx的时候阻止冒泡事件
- viewpager+fragment的懒加载实现微信点击和滑动切换功能(切换效果)
- JavaScript使用键盘输入控制实现数字验证功能
- MySql计数器,如网站点击数,如何实现高性能高并发的计数器功能
- 4个独立按键实现对数码管数字显示的加减清零等
- 自定义Button之实现点击按钮实现倒计时功能
- Cocos2d-x V3.2+Cocos Studio1.6 实现一个简单的uibutton点击功能
- 实现Repeater控件点击表头排序功能
- 简单实现js点击展开二级菜单功能
- C#+AE 实现点击查询属性功能