当前位置:网站首页>Numberpick的功能和用法
Numberpick的功能和用法
2022-07-07 15:40:00 【XLMN】
Numberpick的功能和用法
数值选择器,用于用户输入数值,可通过键盘输入数值,也可通过拖动来选择数值
public class MainActivity extends Activity {
NumberPicker np1, np2;
//定义最小值,最大值的初始值
int minfraction = 140, maxfraction = 150;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.numberpicket);
np1 = findViewById(R.id.numberpicket);
np1.setMaxValue(150);
np1.setMinValue(140);
//设置np1的当前值
np1.setValue(minfraction);
//添加监听器
np1.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
//当numberPICKET发生改变的时候,会激发该方法
@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
minfraction = newVal;
showSelectedPrice();
}
});
np2 = findViewById(R.id.numberpicket01);
np2.setMinValue(145);
np2.setMaxValue(150);
//设置当前值
np2.setValue(maxfraction);
//添加监听器
np2.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
minfraction = newVal;
showSelectedPrice();
}
});
}
private void showSelectedPrice() {
Toast.makeText(this, "你的单科最低分是" + minfraction + "你单科的最高分是" + maxfraction, Toast.LENGTH_LONG).show();
}
}
<?xml version="1.0" encoding="utf-8"?><TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="120dp"
android:layout_height="wrap_content"
android:text="单科最小分数" />
<NumberPicker
android:id="@+id/numberpicket"
android:layout_width="match_parent"
android:layout_height="150dp"
android:focusable="true"
android:focusableInTouchMode="true" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="120dp"
android:layout_height="wrap_content"
android:text="单科最大分数"></TextView>
<NumberPicker
android:id="@+id/numberpicket01"
android:layout_width="match_parent"
android:layout_height="150dp"
android:focusable="true"
android:focusableInTouchMode="true" />
</TableRow>
边栏推荐
- [Huang ah code] Why do I suggest you choose go instead of PHP?
- Flask build API service SQL configuration file
- 服务器彻底坏了,无法修复,如何利用备份无损恢复成虚拟机?
- 【分布式理论】(一)分布式事务
- 麒麟信安云平台全新升级!
- Flash build API Service - generate API documents
- LeetCode 515(C#)
- Lex & yacc of Pisa proxy SQL parsing
- 无法链接远程redis服务器(解决办法百分百)
- Sator推出Web3游戏“Satorspace” ,并上线Huobi
猜你喜欢
With the latest Alibaba P7 technology system, mom doesn't have to worry about me looking for a job anymore
DevOps 的运营和商业利益指南
【可信计算】第十三次课:TPM扩展授权与密钥管理
VSCode关于C语言的3个配置文件
第3章业务功能开发(用户访问项目)
麒麟信安云平台全新升级!
Skimage learning (2) -- RGB to grayscale, RGB to HSV, histogram matching
SlashData开发者工具榜首等你而定!!!
Leetcode brush questions day49
Nerf: the ultimate replacement for deepfake?
随机推荐
LeetCode 648(C#)
Number of exchanges in the 9th Blue Bridge Cup finals
Solidity 开发环境搭建
The server is completely broken and cannot be repaired. How to use backup to restore it into a virtual machine without damage?
【分布式理论】(一)分布式事务
浅谈 Apache Doris FE 处理查询 SQL 源码解析
让保险更“保险”!麒麟信安一云多芯云桌面中标中国人寿, 助力金融保险信息技术创新发展
麒麟信安操作系统衍生产品解决方案 | 存储多路径管理系统,有效提高数据传输可靠性
NeRF:DeepFake的最终替代者?
企业即时通讯软件是什么?它有哪些优势呢?
第二十四届中国科协湖南组委会调研课题组一行莅临麒麟信安调研考察
到底有多二(Lua)
第3章业务功能开发(用户登录)
PLC: automatically correct the data set noise, wash the data set | ICLR 2021 spotlight
服务器彻底坏了,无法修复,如何利用备份无损恢复成虚拟机?
数值 - number(Lua)
User defined view essential knowledge, Android R & D post must ask 30+ advanced interview questions
Shallow understanding Net core routing
L1-027 出租(Lua)
Reflections on "product managers must read: five classic innovative thinking models"