2014-12-03 29 views
0

我在用户提交评级后尝试刷新评级栏时遇到了一些问题。所以基本上我传递现有分级量时,我的其他活动的某些按钮被触发:触发后Android刷新评级栏

viewDtlEventBtn.setOnClickListener(new OnClickListener(){ 
     public void onClick(View v){ 
      Object[] obj = new Object[2]; 
      obj[0] = String.valueOf(eventIDTV.getText()); 
      obj[1] = eventReviewModel; 
      new GetEventDetailAsyncTask(new GetEventDetailAsyncTask.OnRoutineFinished() { 
       public void onFinish() { 
        // Passing whole object with value into another activity 
        Intent eventDtlIntent = new Intent(context, EventDetailMain.class); 
        // Pass in a list of rating star together with amount 
        eventDtlIntent.putExtra("eventPopulateStarObj", populateRatingStar); 
        context.startActivity(eventDtlIntent); 
       } 
      }).execute(obj); 
     } 
    }); 

而且我填充的评价栏时的onCreate():

ratingStarList = (ArrayList<EventReview>) i 
      .getSerializableExtra("eventPopulateStarObj"); 

public void populateRatingProgressBar() { 
    int totalStar = 0; 
    // Get the total amount of rate records 
    for (int j = 0; j < ratingStarList.size(); j++) { 
     if (ratingStarList.get(j).getStarAmt() != null) { 
      totalStar += Integer.parseInt(ratingStarList.get(j) 
        .getStarAmt()); 
     } 
    } 

    txtTotalRate.setText(totalStar + " Ratings for this event");   
    // Set progress bar based on the each rates 
    for (int i = 0; i < ratingStarList.size(); i++) { 
     if (ratingStarList.get(i).getStarAmt() != null) { 
      if (ratingStarList.get(i).getEventReviewRate().equals("5")) { 
       pb5Star.setProgress(Integer.parseInt(ratingStarList.get(i) 
         .getStarAmt())); 
      } else if (ratingStarList.get(i).getEventReviewRate() 
        .equals("4")) { 
       pb4Star.setProgress(Integer.parseInt(ratingStarList.get(i) 
         .getStarAmt())); 
      } else if (ratingStarList.get(i).getEventReviewRate() 
        .equals("3")) { 
       pb3Star.setProgress(Integer.parseInt(ratingStarList.get(i) 
         .getStarAmt())); 
      } else if (ratingStarList.get(i).getEventReviewRate() 
        .equals("2")) { 
       pb2Star.setProgress(Integer.parseInt(ratingStarList.get(i) 
         .getStarAmt())); 
      } else if (ratingStarList.get(i).getEventReviewRate() 
        .equals("1")) { 
       pb1Star.setProgress(Integer.parseInt(ratingStarList.get(i) 
         .getStarAmt())); 
      } 
     } 
    } 
} 

它没有正确填充。但是,我不确定如何在用户提交评分后刷新评分栏。以下是用户提交评级时的代码:

public void promptSubmitStar() { 
    AlertDialog.Builder Dialog = new AlertDialog.Builder(getActivity()); 
    Dialog.setTitle("Confirm Rating"); 
    LayoutInflater li = (LayoutInflater) getActivity().getSystemService(
      Context.LAYOUT_INFLATER_SERVICE); 
    View dialogView = li.inflate(R.layout.option_submit_star, null); 
    txtPromptStarRate = (TextView) dialogView 
      .findViewById(R.id.txtPromptStarRate); 
    txtPromptStarRate.setText("Confirm to submit " + starRate 
      + " stars for this event?"); 
    Dialog.setView(dialogView); 
    Dialog.setPositiveButton("Ok", new DialogInterface.OnClickListener() { 
     public void onClick(DialogInterface dialog, int whichButton) { 
      EventReview eventReviewModel = new EventReview(); 
      eventReviewModel.setEventID(eventID); 
      eventReviewModel.setEventReviewBy(userID); 
      eventReviewModel.setEventReviewRate(String.valueOf(starRate)); 
      new CreateEventReviewAsyncTask(context) 
        .execute(eventReviewModel); 
      dialog.dismiss(); 
      // Disable the rating bar by setting a touch listener which 
      // always return true 
      ratingBar.setOnTouchListener(new OnTouchListener() { 
       public boolean onTouch(View view, MotionEvent event) { 
        return true; 
       } 
      }); 
     } 
    }); 

    Dialog.setNegativeButton("Cancel", 
      new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int whichButton) { 
        dialog.dismiss(); 
       } 
      }); 
    Dialog d = Dialog.show(); 
    EventDialogueBox.customizeDialogueBox(context, d); 
} 

任何想法?提前致谢。

+0

你解决了吗?如果是的话,怎么样? – 2014-12-03 08:38:28

回答

0

使用setRating(starRate);以编程方式在RatingBar上设置评分。

+0

我试图设置一些值给我的进度条,例如:pb5Star.setProgress(1);但它不起作用 – 2014-12-03 04:45:27

+2

这是什么意思,它不起作用?它有什么作用?任何错误 - 在这里发布?更具体,避免像它不工作的答案,因为它不会帮助解决您的问题 – 2014-12-03 05:59:00