I want to make a loop which changes the color of the ImageView but it isn't working..
In the XML file of the Activity I gave some jpg in the background attribute of ImageView
. The colors are from the String Array. Log shows iteration is ok.. It changes ImageView
to white (not visible? )
Code:
public class MainActivity extends AppCompatActivity {
ImageView imV;
int totalStep = 4;
int step = 0;
private Handler handler;
String colors[] = {"#000000", "#ff4455", "#ff1133", "#ff0000", "#00ffff"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imV = (ImageView) findViewById(R.id.imageView);
handler = new Handler();
handler.postDelayed(runnable, 1000);
}
private Runnable runnable = new Runnable() {
@Override
public void run() {
if (step == totalStep) {
step = 0;
} else {
step++;
}
imV.setBackgroundColor(Color.parseColor(colors[step]));
Log.d("Tick", " " + step);
Log.d("color", " _ " + colors[step]);
handler.postDelayed(this, 1000);
}
};
}