Android版的RatingBar获取数据动态 [英] Android RatingBar Fetch Data Dynamically

查看:738
本文介绍了Android版的RatingBar获取数据动态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想强调的基础上,从数据库返回的数据的RatingBar星时有一些问题。所以基本上我有这样的RatingBar:

I am having some problem when trying to highlight the ratingBar star based on the data returned from database. So basically I have this ratingBar:

ratingBar = (RatingBar) eventChat.findViewById(R.id.ratingBar);

然后我进行检查率从数据库中返回,如果不为空,然后我想设置基于整数突出显示的明星:

And then I perform a check for the rates return from database, if not null then I wanted to set the highlighted star based on the integer:

if (reviewModel.getEventReviewRate() != null) {
        existStarRate = Integer.parseInt(reviewModel.getEventReviewRate());
        Log.i("existStarRate", String.valueOf(existStarRate));
    }
    if (existStarRate <= 0) {
        LayerDrawable stars = (LayerDrawable) ratingBar
                .getProgressDrawable();
        stars.getDrawable(2).setColorFilter(
                (context.getResources().getColor(R.color.lightred)),
                PorterDuff.Mode.SRC_ATOP);
        ratingBar.setOnTouchListener(new OnTouchListener() {
            public boolean onTouch(View view, MotionEvent event) {
                return true;
            }
        });
    } 

我自定义突出星级这些codeS:

I customize the highlighted star by these codes:

LayerDrawable stars = (LayerDrawable) ratingBar
                .getProgressDrawable();
        stars.getDrawable(2).setColorFilter(
                (context.getResources().getColor(R.color.lightred)),
                PorterDuff.Mode.SRC_ATOP);

不过,我不知道如何动态地设置突出的明星。比方说,当前从数据库返回的数据是4,我应该把我的RatingBar星4 lightred颜色加以强调。

However, I have no idea how to set the highlighted star dynamically. Let's say currently the data returned from database is 4, I should set 4 of my ratingBar star to be highlighted in lightred color.

任何想法?

先谢谢了。

推荐答案

我已经想通了解决方案了。你可以简单地使用.setRating(int)和它应该在默认的蓝色高亮显示

I've figured out the solution already. You could simply use .setRating(int) and it should be highlighted in default blue color

这篇关于Android版的RatingBar获取数据动态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆