简体   繁体   中英

How do I check if the Android rating bar is empty for a particular object? The null check doesnt seem to working

I have a ratings bar to rate movies and I want to hide the rating bar if there aren't any ratings. I have implemented a null check but that doesnt seem to be working!

float is a primitive data type and not an object. null check is used for objects. For primitives you should use the default values check. For float the default value is 0.0f.

Check link for info

Example

  float x = 0.0f;
 if (x == 0) {
            System.out.println("Value is ZERO>>>>>");
        } else {
            System.out.println("Value is NOT ZERO>>>>>");
        }

我假设您已将模型类的影片分配给等级栏的值,那么您将获得等级(浮点/整数)的值(仅用于确定天气情况以显示等级栏或否)。

This solved the problem, mRating is a string type

 if(Float.parseFloat(mRating)==0)
        {
            Layout.setVisibility(View.GONE);
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM