我在android中使用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("");
}
});
}
}
答案 0 :(得分:2)
考虑到阵列中有五个元素,请执行以下操作。
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
}
});
答案 1 :(得分:0)
你可以使用seekBar.setMax(max)
,其中max = =数组
和paramInt
从数组中获取项目