1

seekbar在安卓中使用。我在string.xml我想要的数组中创建了一个数组,当我移动搜索栏时,只要我移动搜索栏,就应该在文本视图上打印数组的值,文本视图上的值应该被更改。

这是我的代码 -

Java 文件

public class SliderActivity extends Activity 
{
    SeekBar seekbar;
    TextView txt1,txt2;
    String item[];
    int count=0;
    File file;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_PROGRESS);
        setContentView(R.layout.main);
        item=getResources().getStringArray(R.array.myArray);
        seekbar=(SeekBar)findViewById(R.id.seekBar1);
        txt1=(TextView)findViewById(R.id.textView1);
        txt2=(TextView)findViewById(R.id.textView2);
        seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener()
        {
            public void onStopTrackingTouch(SeekBar bar)
            {
                txt2.setText("seekbar has been stop");
            }
            public void onStartTrackingTouch(SeekBar bar)
            {
                txt2.setText("seekbar has started");
            }
            public void onProgressChanged(SeekBar bar,int paramInt, boolean paramBoolean)
            {
                txt1.setText("");
            }
        });
    }
}
4

2 回答 2

2

Considering you have five elements in your array, Do something like this.

seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

    public void onProgressChanged(SeekBar seekBar, int progress,
        boolean fromUser) {
        if (progress <= 20) {


            speed.setText("your Text");
        } else if (progress >= 21 && progress <= 40) {

            speed.setText("your Text");
        } else if (progress >= 41 && progress <= 60) {

            speed.setText("your Text");
        } else if (progress >= 61 && progress <= 80) {

            speed.setText("your Text");
        } else if (progress >= 81 && progress <= 100) {
            speed.setText("your Text");
        }
    }

    public void onStartTrackingTouch(SeekBar arg0) {
        // TODO Auto-generated method stub

    }

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

    }

});
于 2012-05-22T08:08:11.487 回答
0

您可以使用seekBar.setMax(max)where max is = 到数组中的项目编号

paramInt从数组中获取项目

于 2012-05-22T08:00:29.483 回答