- Change of image on ImageView
ImageView iv;//declare as class variable //Change Image to earlyman iv.setImageResource(R.drawable.earlyman);
Here are the partial codes
//#6 Define count , ImageView and movieName int count=0; ImageView iv; String movieName ="First Man"; //#7 bind the xml view with java iv using its id, R.id.imageView1 iv = (ImageView)findViewById(R.id.imageView1); //#8 Show the rating value and movieName on Toast Toast.makeText(MainActivity.this,"Movie Rating is for "+ movieName+ " : "+String.valueOf(ratingBar.getRating()), Toast.LENGTH_SHORT).show();
//#9 Toggle the image after submit button clicked if ( count%2==0) //even number 0,2,4,6 { iv.setImageResource(R.drawable.earlyman); //toggle ImageView to earlyman movieName ="Early Man"; } else { iv.setImageResource(R.drawable.firstman);//toggle ImageView to firstman movieName ="First Man"; } //#10 increase the count and reset ratingBar to zero count++; //increase count by 1 ratingBar.setRating(0);
Demo and explanation of codes
No comments:
Post a Comment
Note: only a member of this blog may post a comment.