想知道通過樣品陣列下面像COLOR1一個爲了該算法循環 - > COLOR3 - >顏色2當按鈕被點擊各一次。我如何週期超過3種類型的值的陣列[機器人]
INT [] colorList =新INT [] {顏色1,顏色2,COLOR3};
目前,我試着做像下面的示例,但無法做到這一點。 如果可能,你會幫我一把嗎?我無法按照我所希望的順序找到解決方案。我很想聽到你的消息!
void updateIndicators(int position) {
for (int i = 0; i < indicators.length; i++) {
indicators[i].setBackgroundResource(
i == position ? R.drawable.indicator_selected : R.drawable.indicator_unselected
);
}
}
爲什麼你在這裏需要一個週期?如果你只有3個項目,只是硬編碼這些indeces ..它將只有3行代碼。這裏使用循環沒有任何好處。 –