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

边栏推荐
猜你喜欢

SlashData开发者工具榜首等你而定!!!

百度地图自定义样式向右拖拽导致全球地图经度0度无法正常显示

Skimage learning (3) -- adapt the gray filter to RGB images, separate colors by immunohistochemical staining, and filter the maximum value of the region

责任链模式 - Unity

【重新理解通信模型】Reactor 模式在 Redis 和 Kafka 中的应用

Skimage learning (2) -- RGB to grayscale, RGB to HSV, histogram matching

Skimage learning (1)

Sator launched Web3 game "satorspace" and launched hoobi

科普达人丨一文弄懂什么是云计算?

Sator launched Web3 game "satorspace" and launched hoobi
随机推荐
Matplotlib绘图界面设置
A tour of grpc:03 - proto serialization / deserialization
PLC:自动纠正数据集噪声,来洗洗数据集吧 | ICLR 2021 Spotlight
How to add aplayer music player in blog
《世界粮食安全和营养状况》报告发布:2021年全球饥饿人口增至8.28亿
【网络攻防原理与技术】第4章:网络扫描技术
centos7安装mysql笔记
责任链模式 - Unity
Flask搭建api服务-SQL配置文件
百度地图自定义样式向右拖拽导致全球地图经度0度无法正常显示
本周小贴士131:特殊成员函数和`= default`
L1-023 输出GPLT(Lua)
本周小贴士#141:注意隐式转换到bool
如何在博客中添加Aplayer音乐播放器
【视频/音频数据处理】上海道宁为您带来Elecard下载、试用、教程
麒麟信安加入宁夏商用密码协会
MySQL usage notes 1
Several best practices for managing VDI
【TPM2.0原理及应用指南】 16、17、18章
【信息安全法律法规】复习篇