سؤال

I am Android novice, hoping my question is clear enough. I have an image and a rating bar at a certain position in an adapter and I add them to a Fragment. I would like the brightness of the image to change as the user changes the ratings on the Ratingbar but have no clue where to begin. This is the function where I instantiate the layout that contains them :

@Override
public Object instantiateItem(ViewGroup container, int position) {

LayoutInflater inflater = (LayoutInflater)container.getContext().getSystemService
(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.rmd1_custom_imageslider_layout, null);   

ImageView image=(ImageView) layout.findViewById(R.id.myimage);             
image.setImageResource(CriteriaImages.get(position));

TextView text=(TextView) layout.findViewById(R.id.myImageViewText);             
text.setText("Rate my "+CriteriaNames.get(position)+" today");

RatingBar rating = (RatingBar) layout.findViewById(R.id.ratingCategory);
rating.setId(position);

Button btn=(Button) layout.findViewById(R.id.done_button);
((ViewPager) container).addView(layout);
return layout; 
}
هل كانت مفيدة؟

المحلول

You have to set a listener, a RatingBar.OnRatingBarChangeListener.

rating.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {

    @Override
    public void onRatingBarChanged( .... ) {

        //DO YOUR STUFF, like setting the alpha value of your image.

    }

}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top