TowTiw TowTiw - 4 months ago 9
Android Question

I want to show the array value one by one (0 to i ) in a text view

I'm a beginner in android development and I want to build a small App that give you the possibility to show the values of an array into the

text view
but I want it to show one and then diapers that the second value then diapers .... that will happen after the
onClick
method :
This is my Java Code :

public void GetMyIdea(View view) {
String testatrix[]={"a","s","d", "f","g"};
TextView tv = (TextView) findViewById(R.id.tv);

for(int l=0; l<1; l++){
tv.append(testatrix[l]);
}


}


this code to me the all values of the array at ones ... I want to show one than the next one then the next one .....

I want to the execution of this code be like that :

1- you enter on the app.
2- you click on the button.
3- than you see in the screen the fist value "a".
4- then you press the button again.
5- the first value "a" will be clean and you see the second value "b".
.
.
. again and again...

Answer

1.oncreate {GetMyIdea(null);} 2. btn click call GetMyIdea(view);

    int index=0;
    public void GetMyIdea(View view)  {
        String testatrix[]={"a","s","d", "f","g"};
        TextView tv = (TextView) findViewById(R.id.tv);


            tv.setText(testatrix[index]);
            if(index>=testatrix.length){
              index=0; 
           }
           else{
            index+=1;

             }
    }