获取android ::中listview中的评级栏值

时间:2015-08-07 08:27:15

标签: android listview ratingbar

我正在尝试在listview中检索ratingbar值(红色星星。)。实际上,我无法保存我的评级值并将其分配给变量,以便我可以将此值设置为我的评级栏。如何纠正此问题并将我的评级栏值保存在变量中,以便评级栏的颜色根据此值更改。

我无法在适配器类中设置它.code如下

            List<StoreReviewRate> apps = new ArrayList<StoreReviewRate>();
                for(int i=0; i<aJson.length(); i++) {
                JSONObject json = aJson.getJSONObject(i);
                StoreReviewRate app = new StoreReviewRate();
                app.setRevCount(json.getString("revcount"));  
                //here is my code to store the rating bar value.But error occur in mystringrate-->[Float.parseFloat(mystringrate);-strOverallRate cannot be resolved to a variable]
                String mystringrate=strOverallRate;
                float rating = Float.parseFloat(mystringrate);  //error occur her strOverallRate cannot be resolved to a variable
                ratingBar.setRating(rating);
                // add the app to apps list
                apps.add(app);

这是我的适配器类。但是我不能接受评级值。我应该在哪里更改?因为它是一个评级栏,我不能给它一个参考。我不知道如何在适配器中设置它。请帮我解决问题。< / p>

     if(app != null) {
    TextView custName = (TextView)v.findViewById(R.id.custnameid);
    TextView cityName = (TextView)v.findViewById(R.id.placeid);
    TextView revCount = (TextView)v.findViewById(R.id.reviewnumid);
    TextView storeReview = (TextView)v.findViewById(R.id.reviewid);
    image =(ImageView)v.findViewById(R.id.imageView1);
    userphoto =(ImageView)v.findViewById(R.id.userphoto);
    //   TextView imageurl = (TextView)v.findViewById(R.id.textView6);

   if(custName != null) custName.setText(app.getFullName());
   if(cityName != null) cityName.setText(app.getCityName()); 
   if(revCount != null) revCount.setText(app. getRevCount());
   if(storeReview != null) storeReview.setText(app. getStoreReview());
   //to display on rating bar UI
   //            String mystringrate=revCount;
   //            float rating = Float.parseFloat(mystringrate);
   //            ratingBar.setRating(rating);

1 个答案:

答案 0 :(得分:-1)

您需要在评级栏上设置监听器。

 ratingBar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {
        @Override
        public void onRatingChanged(RatingBar ratingBar, float rating,
                boolean fromUser) {
            String rated=String.valueOf((int)rating);
        }
    });