17

如何从 a 中获取值SeekBar

  • 我有一个具有三个 SeekBars ( PRICEbar)的类的代码
  • 我想将这些 SeekBars 的值作为 Intents 传递给下一个 Activity(屏幕)
  • 我知道如何实现 OnClickListener,但如何从 SeekBars 中提取值?

例如:如果PRICEbar指向值 10 ...我需要获取 10 的值

过滤器.java

public class Filters extends Activity implements OnSeekBarChangeListener{

    // declare text objects variables
    private SeekBar PRICEbar; 
    private TextView PRICEtextProgress,DISTANCEtextProgress, RATINGtextProgress;
    Button back;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // load the layout
        setContentView(R.layout.filters);   

        PRICEbar = (SeekBar)findViewById(R.id.PRICEseekBarID); // make seekbar object
        PRICEbar.setOnSeekBarChangeListener(this); 
        PRICEbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                // TODO Auto-generated method stub
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
                // TODO Auto-generated method stub
            }

            @Override
            public void onProgressChanged(SeekBar seekBar, int progress,
                    boolean fromUser) {
                // TODO Auto-generated method stub
                PRICEtextProgress = (TextView)findViewById(R.id.PRICEtextViewProgressID);
                PRICEtextProgress.setText("Price:: Rs "+progress);
                seekBar.setMax(100);
            }
        });
    }

    @Override
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        if (seekBar == PRICEbar)
            PRICEtextProgress.setText("Price:: Rs "+progress);
    }

    @Override
    public void onStartTrackingTouch(SeekBar seekBar) {
        // TODO Auto-generated method stub
    }

    @Override
    public void onStopTrackingTouch(SeekBar seekBar) {
        // TODO Auto-generated method stub
    }
}
4

1 回答 1

39

该类SeekBar是 的子类ProgressBar,其中包含一个getProgress()方法。

调用PRICEbar.getProgress()将返回您正在寻找的值。

于 2013-10-07T14:49:58.387 回答