Skip to content Skip to sidebar Skip to footer

Trouble Accessing Inflated Ratingbar In Android

I have an async task that check if a user has a certain item, by checking a database. If they have an item then I inflate a rating bar, if not I inflate a button so they can add th

Solution 1:

I am not sure but assuming you have taken RatingBar in your addrate_layout layout.

If its the case then you have to find RatingBar from the inflated layout.

For exmaple:

mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
Viewview= mInflater.inflate(R.layout.addrate_layout, null);
addListenerOnRatingBar(view);

Modified method by passing View:

publicvoidaddListenerOnRatingBar(View view) {

        RatingBarratingBar= (RatingBar) view.findViewById(R.id.beerRatingBar);


        //if rating value is changed,//display the current rating value in the result (textview) automatically
        ratingBar.setOnRatingBarChangeListener(newOnRatingBarChangeListener() {
            publicvoidonRatingChanged(RatingBar ratingBar, float rating,
                boolean fromUser) {

                //next async task to update online database

            }
        });
      }

Post a Comment for "Trouble Accessing Inflated Ratingbar In Android"