将NumberPicker值添加到数据库

时间:2014-10-03 19:46:44

标签: 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

2 个答案:

答案 0 :(得分:1)

您是否尝试过保存:

  Integer.toString(inputTime.getValue());

答案 1 :(得分:0)

我为我的NumberPicker调用了setOnValueChangedListener并使用该值添加到我的数据库中。我把代码放到了问题的更新中。感谢。

相关问题