Tramping array textviews Android
I want to display phrases from a pre-defined array (array.xml) in a开发者_开发技巧 TextView and would like to traverse this array from front to back with buttons. How can I do this?
Thank you.
Resources res = getResources();
myPiada = res.getStringArray(R.array.curtas);
TextView tva = (TextView) findViewById(R.id.piadas);
What part of this? What have you tried to do? First you have to set up the layout with buttons, then set up click handlers to these buttons to set the text on the TextView to the previous or next item in the array.
For example, if your TextView is currently set to position "i", your "Next" button should setText(myPiada[i++])
, "Previous" should setText(myPiada[i--])
. You'll also need to check and make sure that if i = 0, the previous button is disabled, or if i = myPiada.length, the next button is disabled.
精彩评论