java - 将 NumberPicker 值添加到数据库

标签 java android parse-platform numberpicker

更新,我终于通过调用 onValueChangedListener 完成了这项工作。

     layout.setLayoutParams(params);
    final EditText input = new EditText(MainActivity.this);
    final EditText inputNotes = new EditText(MainActivity.this);

    final NumberPicker inputCount = new NumberPicker(MainActivity.this);
    inputCount.setMaxValue(50);
    inputCount.setMinValue(0);
    inputCount.clearFocus();
    inputCount.setOnValueChangedListener( new NumberPicker.
            OnValueChangeListener() {
            @Override
            public void onValueChange(NumberPicker picker, int
                oldVal, int newVal) {

            }
        });

当我发布到 Parse.com 数据库时调用该值。谢谢。

public void onClick(DialogInterface dialog, int which) {
        // Create a post.
        AnywallPost post = new AnywallPost();
        // Set the location to the current user's location
        post.setLocation(myPoint);
        post.setText(input.getText().toString());
        post.setNotes(inputNotes.getText().toString());

        final int valueCount = inputCount.getValue(); //getting valueCount from above
        post.setNumber(valueCount); 

结束更新。

我想将 NumberPicker 中的值添加到我为应用程序设置的后端 Parse.com 数据库中。我已将 NumberPicker 添加到 Post 表单中。当我保存帖子后查看表格时,我没有看到数字,而是看到了无意义的文本条目。有人对我需要添加到代码中的内容有建议吗?谢谢。

MainActivity 中的 NumberPicker 代码:

    layout.setLayoutParams(params);
    final EditText input = new EditText(MainActivity.this);
    final EditText inputNotes = new EditText(MainActivity.this);
    final NumberPicker inputCount = new NumberPicker(MainActivity.this);
    inputCount.setMinValue(0);
    inputCount.setMaxValue(50);

我正在使用 MainActivity 中的代码进一步保存输入。

 public void onClick(DialogInterface dialog, int which) {
        // Create a post.
        AnywallPost post = new AnywallPost();
        // Set the location to the current user's location
        post.setLocation(myPoint);
        post.setText(input.getText().toString());
        post.setNotes(inputNotes.getText().toString());

        post.setNumber(inputCount.getContext().toString()); //This is where value for NumberPicker is saved. I need to change this line, I think.

带有 NumberPicker 的 Post 表单:

enter image description here

我还没有使用 NumberPicker 值填充 Parse.com 表。它会向该字段写入类似 com.parse.anywall.MainActivity... 的内容。

enter image description here

最佳答案

您是否尝试过保存:

  Integer.toString(inputTime.getValue());

关于java - 将 NumberPicker 值添加到数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26185746/

相关文章:

java - JPA - 注入(inject)或实例化自定义属性/对象以进行 JSF 写访问?

在较旧的 Oracle 版本中编译的 Java 代码在 Oracle 12.2 中出现编译错误

ios - 如何在子类中设置只读属性?

java - 如何从网络服务器下载图像到java SE应用程序

java - 是否可以从 URL 向 Elastic Search 插入数据?

javascript - meteor 跑安卓

android - 如何在android studio中设置库

php - 使用 Retrofit 2 将 Pdf 上传到服务器

iOS 如何在数组解析Swift中从数据库下载数据

javascript - 将文件上传到 Parse (Javascript)