jeudi 2 avril 2015

Incremental values how to show one value at a time

I am making a simple sequence from randomly generated numbers. Each number will show an image linked to it. for example,


the value 1 will show a picture of a cat. value 2 a dog and value 3 a mouse.


Each image has it's own dedicated imageview, the layout looks like this by default, i.e image views that store black until it's number is called:


enter image description here


Each time the sequence increments. so on the second run two images will show, on the third 3 will show and so on.


The problem I am having is that all the images show at once. So for sequence one just the one image flashes (which is what I want). but on the second run both images show at once together instead of showing the first image then the second.


So to clarify let's say on the four runs the stored array is 1,2,3,3 I would want


image 1 to show, and disappear.then image 2 show and disappear. then image 3 show and disappear and then image 3 to show and disappear.


But what I actually get is on the fourth run 1,2&3 will show at once and disappear at the same time together. How can I break this up to achieve what I want. I have tried many methods and the same result happens. I can't get my head around this problem.


Here is my code:



ArrayList<Integer> stored_vals = new ArrayList<Integer>();
public void Gen() {

int i=0 ;

Random rand = new Random();
int rndInt = rand.nextInt(3)+ 1 ;
list.add(rndInt);
int totalElements = list.size();
Log.d("LOOK", Integer.toString(rndInt));
Log.i("VALUE LIST ", list.toString()+" <<<<LIST HERE");

final CounterClass Reset_View = new CounterClass(1000 , 0010);

while(i < totalElements) {

retval =list.get(i);

Log.d("RETVAL", Integer.toString(retval));
String imgName = "flash" + retval;
int id = getResources().getIdentifier(imgName, "drawable", getPackageName());

if (retval==1){

Cat.setImageResource(id);
Reset_View();
}
else if (retval==2){
Dog.setImageResource(id);
Reset_View();
}
else if (retval==3){
Mouse.setImageResource(id);
Reset_View();
}

i++;
}

}


To try and delay the images showing at one at a time and to reset to it's default after showing for a few seconds I call Reset_View(); which is the following code:



public class Reset_View(); extends CountDownTimer {
public CounterClass(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}
@Override // when timer is finished
public void onFinish() {
Dog.setImageResource(R.drawable.Black);
Cat.setImageResource(R.drawable.Black);
Mouse.setImageResource(R.drawable.Black);
}
@Override
public void onTick(long millisUntilFinished) {
// TODO Auto-generated method stub
}
}


So how can I achieve what I want. I have been stuck on this idea for weeks.


Aucun commentaire:

Enregistrer un commentaire