在滑块上使用移动效果时出现问题

时间:2013-11-26 10:34:36

标签: blackberry

这里我在滑块上使用了值变化效果;如果我移动滑块,它将按照滑块的移动滚动并在编辑字段中显示更新的值。此外,还有一个编辑字段效果,其中滑块应根据输入编辑字段的值移动;但它没有用。

当我注释掉部分编辑字段效果时,它正常工作,但是当我再次应用该编辑字段效果时,它就无法正常工作......

//滑块移动

    FieldChangeListener listenerslider1 = new FieldChangeListener() {

        public void fieldChanged(Field field, int context) {
            try {

                if (field == serumosmslider) {

                    int serumosmslidervalue = serumosmslider.getValue();
                    String strplasmaslidervalue = Integer
                            .toString(serumosmslidervalue);
                    edtserumosm.setText(strplasmaslidervalue);

                }

            } catch (IllegalStateException e) {

                e.printStackTrace();
            } catch (NullPointerException e) {
                e.printStackTrace();
            }
        }
    };

    serumosmslider.setChangeListener(listenerslider1);

// for editfield

    FieldChangeListener listenereditslider1 = new FieldChangeListener() {

        public void fieldChanged(Field field, int context) {

            hfmslider1.deleteAll();
            String stredtweight = edtserumosm.getText().toString();

            int editweight = Integer.parseInt(stredtweight);

                SliderField theSlider = new SliderField(slider2thumb,
                        slider2progress, slider2base, slider2thumbfoc,
                        slider2progressfoc, slider2basefoc, 201,
                        editweight, 10, 10);
                hfmslider1.add(theSlider);
                hfmslider1.invalidate();


        }

    };

    edtserumosm.setChangeListener(listenereditslider1);

1 个答案:

答案 0 :(得分:1)

每当SliderField的值发生变化时,您似乎正在重新创建EditField

    SliderField theSlider = new SliderField(slider2thumb,
           slider2progress, slider2base, slider2thumbfoc,
           slider2progressfoc, slider2basefoc, 201,
           editweight, 10, 10);
    hfmslider1.add(theSlider);

我认为你不想这样做。就像您在滑块字段更改时更新 EditField文本一样,我认为您应该在SliderField更新 EditField值文字改变了。所以,像这样:

FieldChangeListener listenereditslider1 = new FieldChangeListener() {

    public void fieldChanged(Field field, int context) {

        if (field == edtserumosm && context != FieldChangeListener.PROGRAMMATIC) {

            String stredtweight = edtserumosm.getText().toString();

            try {
                int editweight = Integer.parseInt(stredtweight);
                serumosmslider.setValue(editweight);
            } catch (NumberFormatException nfe) {
                // TODO: anything?
            }
        }
    }

};

edtserumosm.setChangeListener(listenereditslider1);