安卓:按按钮单击显示值的数组一前一后 [英] Android: display the array of values one after the other according to the button click
问题描述
我有12个整数值的数组,我想要显示它一前一后像
I have an array of 12 integer values and I want to display it one after the other like
最初的应用程序运行,我显示6个值。
Initially on application run I am displaying 6 values.
按钮点击我要显示的其他6个值逐一
on the button click I want to display the other 6 values one by one
prevbutton-> 值1 值2 VALUE3 VALUE4 值5 < STRONG> value6 - > Next按钮
prevbutton-> value1 value2 value3 value4 value5 value6 -> nextbutton
等下一步按钮单击它应该是这样的。
so on next button click it should be like this.
接下来的6值应显示这样的
next 6 values should be displayed like this
prevbutton - > 值2 VALUE3 VALUE4 值5 value6 value7 - > Next按钮
prevbutton-> value2 value3 value4 value5 value6 value7 -> nextbutton
本应持续到12值
和扭转的 prevbutton的情况下,应该发生的。
帮助总是AP preciated,谢谢
Help is always appreciated, Thanks
我显示前6个值这样的
public void autoTune() {
Log.i("autotune", " called");
if (frequency[0] == 0.0)
station1.setText("");
else
station1.setText("" + frequency[0]);
if (frequency[1] == 0.0)
station2.setText("");
else
station2.setText("" + frequency[1]);
if (frequency[2] == 0.0)
station3.setText("");
else
station3.setText("" + frequency[2]);
if (frequency[3] == 0.0)
station4.setText("");
else
station4.setText("" + frequency[3]);
if (frequency[4] == 0.0)
station5.setText("");
else
station5.setText("" + frequency[4]);
if (frequency[5] == 0.0)
station6.setText("");
else
station6.setText("" + frequency[5]);
}
@Override
protected Boolean doInBackground(Context... params) {
// TODO Auto-generated method stub
Log.i("in autotune", " before freq length");
int[] freq = { 911, 943, 947, 932, 901, 964, 843, 835, 946,904,908,873,877 };
freqCounter = 0;
Log.i("in autotune", "after freq length : " + freq.length);
frequency = new double[freq.length];
Log.i("in autotune", "after frequency length : " + frequency.length);
for (int k = 0; k < freq.length; k++) {
Log.i("In Radio.java", "Freq : " + freq[k]);
frequency[k] = freq[k];
frequency[k] = frequency[k] / 10;
if (frequency[k] == 0.0)
break;
freqCounter++;
Log.i("In Radio.java", "Frequency : " + frequency[k]);
}
我曾尝试与该code但这不是在所有工作
I have tried with this code but this is not working at all
public void forwardtune(){
Button[] buttons = new Button[5];
buttons[0] = (Button)findViewById(R.id.radiostation1);
buttons[1] = (Button)findViewById(R.id.radiostation2);
buttons[2] = (Button)findViewById(R.id.radiostation3);
buttons[3] = (Button)findViewById(R.id.radiostation4);
buttons[4] = (Button)findViewById(R.id.radiostation5);
buttons[5] = (Button)findViewById(R.id.radiostation6);
if(currentlyDisplayingFromPosition + 6 >= arraySize)
return;
for(int i=0; i<arraySize; i++){
buttons[i].setText("");
}
for(int i=currentlyDisplayingFromPosition; i<=currentlyDisplayingFromPosition+6; i++){
if (frequency[i] == 0.0)
buttons[i].setText("");
else
buttons[i].setText("" + frequency[0]);
}
}
我在调用这个函数forwardtune()在单击下一步按钮。仍然没有运气!有什么建议?
I am calling this function forwardtune() in next button click. still no luck! any suggestions?
推荐答案
您可以通过这个尝试。
int currentlyDisplayingFromPosition = 0;
int arraySize = 12;
public void forwardTune(){
if(currentlyDisplayingFromPosition + 6 >= arraySize)
return;
for(int i=0; i<arraySize; i++){
textView[i].setText("");
}
for(int i=currentlyDisplayingFromPosition; i<=currentlyDisplayingFromPosition+6; i++){
if (frequency[i] == 0.0)
textView[i].setText("");
else
textView[i].setText("" + frequency[0]);
}
}
同样可以尝试backwardTune()也与上述相反的code。
similarly you can try for backwardTune() also by reversing the above code.
这篇关于安卓:按按钮单击显示值的数组一前一后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!