gpt4 book ai didi

安卓搜索栏

转载 作者:行者123 更新时间:2023-11-29 22:06:26 26 4
gpt4 key购买 nike

我在 android 中使用 seekbar。我在 string.xml 中创建了一个数组 我希望当我移动搜索栏时,数组的值应该打印在 TextView 上,只要我移动搜索栏 TextView 上的值应该被改变。

这是我的代码 -

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("");
}
});
}
}

最佳答案

考虑到你的数组中有五个元素,做这样的事情。

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

}

});

关于安卓搜索栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10697894/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com