Friday 15 January 2010

java - My button for previous ImageView image does not work -


I have two buttons and an image view when I click on the next button, it goes from the painting folder to the next image is. But the previous button is not working. I do not know why, I think my argument is correct. Here's my code:

  Public class Photo_gallery activity tool extends OnClickListener {button next, last; Image view slika; Int a = 0; @ Override protected void saved create (bundled Instansstet) {Suprknkret (saved Instensstet); SetContentView (R.layout.photo_gallery); InicijalizujVarijable (); } Private Zero InicijalizujVarijable () {Next = (Button) findViewById (R.id.bNext); Find Previous = (Button) VVBIID (RID BPP); Slika = (ImageView) findViewById (R.id.imageView1); Next.setOnClickListener (this); Previous.setOnClickListener (this); } Click on Public Zero (see V) {Switch (v.getId ()} {Case RID: Binfection: if (a == 0) {slika.setImageResource (R.drawable.p2); A = 1; } And if (a == 1) {slika.setImageResource (R.drawable.p3); A = 2; } And if (a == 2) {slika.setImageResource (R.drawable.p4); A = 3; . . . . } And if (a == 56) {startActivity (new intent ("com.example.apps.MENU")); End(); } break; Case R.id.b East: a--; Next.performClick (); break; }}    

Why do not you do this by creating a function

  Click Public Zero (see V) {switch (v.getId ()) {case R.id.bNext: /// Calling function; SetImage (a); break; Case R.id.b Pre: if (A & gt; 0) {a--; SetImage (a); break; }}} Private Zero Setizes (int a) {if (a == 0) {slika.setImageResource (R.drawable.p2); } And if (a == 1) {slika.setImageResource (R.drawable.p3); } And if (a == 2) {slika.setImageResource (R.drawable.p4); . . . . } And if (a == 56) {startActivity (new intent ("com.example.apps.MENU")); End(); }}   

edit increase and subtraction onClick method by a ++ and a - Remember to start with your int a = -1 but by the time you do not click on nextPicture , the default picture will be redundant - it will always be one for you Dynamic dynamic means i.e. Instead of starting with a price, it is increasing with ++ or - like a = 21 not preferred < / Div>

No comments:

Post a Comment