当前位置:网站首页>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>

边栏推荐
- 从DevOps到MLOps:IT工具怎样向AI工具进化?
- 【网络攻防原理与技术】第1章:绪论
- 科普达人丨一文弄懂什么是云计算?
- Flash build API Service - generate API documents
- 阿富汗临时政府安全部队对极端组织“伊斯兰国”一处藏匿点展开军事行动
- 【可信计算】第十二次课:TPM授权与会话
- MySQL implements the query of merging two fields into one field
- Solidity 开发环境搭建
- 麒麟信安中标国网新一代调度项目!
- [Seaborn] combination chart: facetgrid, jointgrid, pairgrid
猜你喜欢
随机推荐
mysql实现两个字段合并成一个字段查询
【饭谈】如何设计好一款测试平台?
《世界粮食安全和营养状况》报告发布:2021年全球饥饿人口增至8.28亿
99% 用户在 Power BI 云端报表常犯错误
VSCode关于C语言的3个配置文件
服务器彻底坏了,无法修复,如何利用备份无损恢复成虚拟机?
本周小贴士131:特殊成员函数和`= default`
Skimage learning (2) -- RGB to grayscale, RGB to HSV, histogram matching
Establishment of solid development environment
Notes on installing MySQL in centos7
PLC: automatically correct the data set noise, wash the data set | ICLR 2021 spotlight
让保险更“保险”!麒麟信安一云多芯云桌面中标中国人寿, 助力金融保险信息技术创新发展
[fan Tan] those stories that seem to be thinking of the company but are actually very selfish (I: building wheels)
Devops' operational and commercial benefits Guide
本周小贴士#136:无序容器
[Seaborn] combination chart: pairplot and jointplot
到底有多二(Lua)
麒麟信安携异构融合云金融信创解决方案亮相第十五届湖南地区金融科技交流会
Sator launched Web3 game "satorspace" and launched hoobi
国内首创!Todesk将RTC技术融入远程桌面,画质更清晰操作更流畅









