- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想从我的 numberpicker 中获取值,但我的 numberpicker.getvalue() 不起作用。
这是我的java
public class MakananIndoVer1 extends AppCompatActivity {
private CoordinatorLayout coordinatorLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_makanan_indo_ver1);
coordinatorLayout = findViewById(R.id.CoordinatorLayout);
final NumberPicker picker = (NumberPicker) findViewById(R.id.number_picker_default);
picker.setMax(15);
picker.setMin(0);
picker.setUnit(1);
picker.setValue(0);
picker.setValueChangedListener(new ValueChangedListener() {
@Override
public void valueChanged(int value, ActionEnum action) {
Toast.makeText(MakananIndoVer1.this, picker.getValue(), Toast.LENGTH_SHORT).show();
}
});
}
}
这是我的 logcat
2019-01-03 17:16:09.006 1563-3245/? W/audio_hw_generic: Not supplying enough data to HAL, expected position 1336405 , only wrote 1336320
2019-01-03 17:16:09.009 4907-4907/com.example.denny.prodia D/AndroidRuntime: Shutting down VM
--------- beginning of crash
2019-01-03 17:16:09.079 4907-4907/com.example.denny.prodia E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.denny.prodia, PID: 4907
java.lang.ClassCastException: android.content.res.Resources cannot be cast to java.lang.CharSequence
at com.example.denny.prodia.MakananIndoVer1$1.valueChanged(MakananIndoVer1.java:34)
at com.travijuu.numberpicker.library.NumberPicker.changeValueBy(NumberPicker.java:225)
at com.travijuu.numberpicker.library.NumberPicker.increment(NumberPicker.java:204)
at com.travijuu.numberpicker.library.Listener.ActionListener.onClick(ActionListener.java:40)
at android.view.View.performClick(View.java:6597)
at android.view.View.performClickInternal(View.java:6574)
at android.view.View.access$3100(View.java:778)
at android.view.View$PerformClick.run(View.java:25885)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
--------- beginning of system
2019-01-03 17:16:09.196 1819-4593/? W/ActivityManager: Force finishing activity com.example.denny.prodia/.MakananIndoVer1
2019-01-03 17:16:09.222 1819-1834/? W/BroadcastQueue: Background execution not allowed: receiving Intent { act=android.intent.action.DROPBOX_ENTRY_ADDED flg=0x10 (has extras) } to com.google.android.gms/.stats.service.DropBoxEntryAddedReceiver
2019-01-03 17:16:09.223 1819-1834/? W/BroadcastQueue: Background execution not allowed: receiving Intent { act=android.intent.action.DROPBOX_ENTRY_ADDED flg=0x10 (has extras) } to com.google.android.gms/.chimera.GmsIntentOperationService$PersistentTrustedReceiver
2019-01-03 17:16:09.227 4907-4907/com.example.denny.prodia I/Process: Sending signal. PID: 4907 SIG: 9
2019-01-03 17:16:09.268 2599-2612/? W/gle.android.gm: Couldn't lock the profile file /data/misc/profiles/cur/0/com.google.android.gms/primary.prof: Failed to lock file '/data/misc/profiles/cur/0/com.google.android.gms/primary.prof': Try again
2019-01-03 17:16:09.268 2599-2612/? W/gle.android.gm: Could not forcefully load profile /data/misc/profiles/cur/0/com.google.android.gms/primary.prof
2019-01-03 17:16:09.291 1819-1895/? W/InputDispatcher: channel '62146ad com.example.denny.prodia/com.example.denny.prodia.MakananIndoVer1 (server)' ~ Consumer closed input channel or an error occurred. events=0x9
2019-01-03 17:16:09.291 1819-1895/? E/InputDispatcher: channel '62146ad com.example.denny.prodia/com.example.denny.prodia.MakananIndoVer1 (server)' ~ Channel is unrecoverably broken and will be disposed!
2019-01-03 17:16:09.291 1819-1895/? W/InputDispatcher: channel 'e7decf7 com.example.denny.prodia/com.example.denny.prodia.MenuMakananUtama (server)' ~ Consumer closed input channel or an error occurred. events=0x9
2019-01-03 17:16:09.291 1819-1895/? E/InputDispatcher: channel 'e7decf7 com.example.denny.prodia/com.example.denny.prodia.MenuMakananUtama (server)' ~ Channel is unrecoverably broken and will be disposed!
2019-01-03 17:16:09.291 1819-1895/? W/InputDispatcher: channel '12dd43d com.example.denny.prodia/com.example.denny.prodia.MakananKhasIndo (server)' ~ Consumer closed input channel or an error occurred. events=0x9
2019-01-03 17:16:09.291 1819-1895/? E/InputDispatcher: channel '12dd43d com.example.denny.prodia/com.example.denny.prodia.MakananKhasIndo (server)' ~ Channel is unrecoverably broken and will be disposed!
2019-01-03 17:16:09.291 1819-1895/? W/InputDispatcher: channel 'eff06b com.example.denny.prodia/com.example.denny.prodia.MenuUtama (server)' ~ Consumer closed input channel or an error occurred. events=0x9
2019-01-03 17:16:09.291 1819-1895/? E/InputDispatcher: channel 'eff06b com.example.denny.prodia/com.example.denny.prodia.MenuUtama (server)' ~ Channel is unrecoverably broken and will be disposed!
2019-01-03 17:16:09.293 1668-1668/? I/Zygote: Process 4907 exited due to signal (9)
在这里我想查看我的数字选择器中的值。但是,我只知道我的 picker.getvalue() 是错误的并破坏了我的模拟器。我只是想知道在哪里可以修复错误。
最佳答案
方法 makeText()
有多个重载。
您想使用这个:
public static Toast makeText(Context context, CharSequence text, @Duration int duration) {
return makeText(context, null, text, duration);
}
但是因为您传递了 picker.getValue()
这是一个整数值,
编译器使用了这个:
public static Toast makeText(Context context, @StringRes int resId, @Duration int duration)
throws Resources.NotFoundException {
return makeText(context, context.getResources().getText(resId), duration);
}
如您所见,它采用一个整数作为第二个参数,但该整数被解释为资源 ID。
因此应用程序崩溃,因为没有值为 picker.getValue()
的资源 ID。
您只需将传递的第二个参数设为String
:
Toast.makeText(MakananIndoVer1.this, String.ValueOf(picker.getValue()), Toast.LENGTH_SHORT).show();
或
Toast.makeText(MakananIndoVer1.this, "" + picker.getValue(), Toast.LENGTH_SHORT).show();
关于java - 为什么 numberpicker.getvalue() 没有得到返回值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54020449/
我有一个使用 NumberPicker 的应用程序。由于该应用程序支持旧版本的 Android,其中没有 NumberPicker 小部件可用,我必须使用 external library . 在我的
该应用程序包含两个 Activity ,FirstScreen 和 SecondScreen。 FirstScreen 包含一个 NumberPicker np1 和一个按钮 toSecondScre
我有一个 NumberPicker 实例,它按预期工作,但我需要在滚动停止时或当用户仅按下增量/减量按钮时从中获取值。我应该得到的值显示在 TextView 中。 当滚动停止/变得空闲并正确显示时,我
我在 fragment 中使用 Android SDK 级别 13 下的 NumberPicker。工作正常,但每次 Activity 开始时,光标都会在数字后面闪烁。我怎样才能摆脱闪烁的光标,我不知
我正在尝试在数字选择器中添加数据列表。我正在使用的库:https://github.com/ShawnLin013/NumberPicker对于数字选择器。 这就是它在我的应用程序中的显示方式: 正如
我正在尝试在 Android 中创建一个数字选择器,但轮子只增加 1。我想增加 0.1。我在网上查了一下,但我发现了一个格式化的浮点数组禁用了轮子。请帮助并为语法感到抱歉,我正在学习。 最佳答案 您可
我的 NumberPicker 在 setDescendantFocusability(FOCUS_BLOCK_DESCENDANTS) 模式下关闭了 setWrapSelectorWheel(fal
我在 AlertDialog 中有一个 NumberPicker 实例化如下:final NumberPicker np = new NumberPicker(PiattoActivity.this)
我正在尝试在自定义对话框中填充 NumberPicker。目前我正在使用一种方法,该方法使用 View 并扩展另一个布局(对话框),该方法应该填充 NumberPicker 但是当我在 onCreat
我使用了一个稍微修改过的 NumberPicker,当 Activity 开始时,默认值已经被选中。这很烦人,因为它会调出键盘或调出用于剪切/复制/粘贴的对话框。我确实指示键盘保持按下状态,但它仍处于
我在一个布局中有两个数字选择器,我正在使用一个 AlertDialog Box 的布局。但是,这两个数字选择器没有用于增加/减少值的滚动条。我也无法手动输入值。谁能帮我找出错误。 对话框.xml
我找到了 2 个内置的 NumberPickers: (来源:techbooster.org) 默认情况下,它是第一个,但是当我在 AndroidManifest.xml 中添加 android:th
你好, 我遇到了这个问题:我需要我的用户在 1 到 9 之间选择一个数字,但是 NumberPicker(如上所示)看起来非常丑陋,所有其他选择也好不到哪里去。您有其他选择吗? 非常感谢... 最佳答
这个问题在这里已经有了答案: How to create a negative NumberPicker (4 个答案) 关闭 6 年前。 我正在尝试为我的 NumberPicker 使用一组数字,
我有一个关于 Android NumberPicker 的问题。当用户在 NumberPicker 上执行 Fling 时,对于每一步,都会触发 OnValueChange 的监听器。我能否以这种方式
我正在使用三个 NumberPickers 在不同的日历系统中创建一个 DatePicker,并尝试将字体设置为 NumberPicker 控件。根据 this在 SO 上发帖,我查看了 number
我正在使用 NumberPicker。但默认情况下它处于垂直模式。我可以设置为水平模式吗? 这是我的 NumberPicker: 最佳答案 在找不到解决方案后,我决定自己实现。它是带选择轮的版本,不
我想帮助我开发一个带有从 firebase 获得的列表的数字选择器,此代码现在给我一个错误,如果我删除“setMaxValue 和 MinValue”,它只会给我带来一个值。 CBSList
在 activity_main.xml 中: 在 MainActivity.java 里面的 oncreate : NumberPicker numberPicker1 = (NumberPicke
我与 NumberPicker 安全问题对话。长文本被截断。如何解决这个问题? 这是对话框的布局内容 最佳答案 我遇到了同样的问题。我设法通过给 NumberPicker 一个大的 layou
我是一名优秀的程序员,十分优秀!