0

我想将评级 - 将由用户在 DIALOG 的评级栏上设置 - 传递给活动的评级栏。(我设置了 2 个带有 2 个不同评分栏的 xml)

你能帮助(用代码)我怎么能做到这一点?提前致谢。

public class RecipesDetails  extends Activity implements OnClickListener, OnRatingBarChangeListener{

    TextView rTitle, rType, rSubName, reviewAmount;
    Button aRating; 
    RatingBar getNewRating, setRatingBar;
    int count;
    float curRate;

    private static final int DIALOG_TEXT_ENTRY_RATE = 1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView (R.layout.recipes_detail);
        initialize();

        aRating.setOnClickListener(this);

        rTitle.setText(getIntent().getExtras().getString("rec_name"));
        rType.setText(getIntent().getExtras().getString("current_rating"));
        rSubName.setText(getIntent().getExtras().getString("sub_name"));

        setRatingBar.setRating(curRate);
        getNewRating.setOnRatingBarChangeListener(this);
    }

    private void initialize() {
        // TODO Auto-generated method stub
        rTitle = (TextView) findViewById(R.id.tvDetailRecipeTitle);
        rType = (TextView) findViewById(R.id.tv_detail_recipe_Rating);
        rSubName = (TextView) findViewById(R.id.tv_detail_recipe_SubmittedName);

        aRating = (Button) findViewById (R.id.bAddReview);

        getNewRating = (RatingBar) findViewById (R.id.detail_recipe_ratingBar);
        setRatingBar = (RatingBar) findViewById (R.id.dialogRatingBar);
        reviewAmount = (TextView) findViewById (R.id.tv_detail_recipe_Rating);

    }

    @SuppressWarnings("deprecation")
    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        switch(v.getId()){
        case R.id.bAddReview:
        showDialog(DIALOG_TEXT_ENTRY_RATE);
            break;
        }

    }


    @Override
    public void onRatingChanged(RatingBar ratingBar, float rating,
            boolean fromUser) {
        // TODO Auto-generated method stub
        DecimalFormat decimalFormat = new DecimalFormat("#.#");
        curRate = Float.valueOf(decimalFormat.format((curRate * count + rating)
                / ++count));
        Toast.makeText(RecipesDetails.this,
                "New Rating: " + curRate, Toast.LENGTH_SHORT).show();
        setRatingBar.setRating(curRate);
        reviewAmount.setText(count + " Ratings");

    }

    protected Dialog onCreateDialog(int id) {
        switch (id) {
        case DIALOG_TEXT_ENTRY_RATE:
            LayoutInflater acc = LayoutInflater.from(this);
            final View textEntryViewAcc = acc.inflate(R.layout.add_rating_dialog, null);
            final RatingBar rateME = (RatingBar) textEntryViewAcc.findViewById(R.id.detail_recipe_ratingBar);
            //final EditText amountofwater = (EditText) textEntryViewAcc.findViewById(R.id.etGlasesOfWater);
            return new AlertDialog.Builder(RecipesDetails.this)
                    //.setIconAttribute(android.R.attr.alertDialogIcon)
                    .setTitle(R.string.alert_dialog_add_review)
                    .setView(textEntryViewAcc)
                    .setPositiveButton(R.string.alert_dialog_submit,
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog,
                                        int whichButton) {

                                    /* User clicked OK so do some stuff */
                                }
                            })
                    .setNegativeButton(R.string.alert_dialog_cancel,
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog,
                                        int whichButton) {

                                    /* User clicked cancel so do some stuff */
                                }
                            })

                            .create();

        }
        return null;
        }

}

我需要将 onRatingChanged 方法中的内容移动到正面按钮部分的对话框中,但不知道该怎么做......

4

0 回答 0