![](/img/trans.png)
[英]Passing a FLOAT value from a ratingBar from one fragment to another
[英]ratingbar does not filled the float value coming from JSON android
问题是,如果评级是 3.5,那么评级栏最多填充 3 颗星......它没有填充第四颗星的一半......
我不知道我哪里出错了需要帮助谢谢:以下是我的代码
评分:
<RatingBar
android:numStars="5"
android:id="@+id/ratingbar"
android:layout_width="wrap_content"
android:clickable="false"
android:isIndicator="true"
android:layout_height="45dp"
android:focusableInTouchMode="false"
android:defaultFocusHighlightEnabled="false"
android:focusable="false"
android:progressBackgroundTint="#7F7F7F"
android:progressTint="#FFBA00"
android:stepSize="0.5"
/>
这是我的适配器:-不发布完整代码只是一个重要部分
override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
holder.productname.text = Tablelist.get(position).name
holder.producername.text = Tablelist.get(position).producer
holder.productprice.text = Tablelist.get(position).cost.toString()
Glide.with(context).load(Tablelist.get(position).product_images)
.into(holder.image)
holder.rate.setRating(Tablelist.get(position).rating);
// holder.rate.setStepSize(Tablelist.get(position).rating);// to show to stars
holder.itemView!!.setOnClickListener {
val context:Context=holder.itemView.context
val i=Intent(context,
Product_details::class.java)
i.putExtra("id",Tablelist.get(position).id.toString())
Log.e("checkid",Tablelist.get(position).id.toString())
context.startActivity(i)
}
}
fun setMovieListItems(movieList: List<Table_data>){
this.Tablelist = movieList;
notifyDataSetChanged()
}
class MyViewHolder(itemView: View?) : RecyclerView.ViewHolder(itemView!!) {
val productname: TextView = itemView!!.findViewById(R.id.title)
val producername: TextView = itemView!!.findViewById(R.id.title1)
val productprice: TextView = itemView!!.findViewById(R.id.title2)
val rate: RatingBar=itemView!!.findViewById(R.id.ratingbar)
val image: ImageView = itemView!!.findViewById(R.id.image)
}
这是我的表列表:
data class Table_data (
@SerializedName("id") val id : Int,
@SerializedName("product_category_id") val product_category_id : Int,
@SerializedName("name") val name : String,
@SerializedName("producer") val producer : String,
@SerializedName("description") val description : String,
@SerializedName("cost") val cost : Int,
@SerializedName("rating") val rating : Float=0.0f,
@SerializedName("view_count") val view_count : Int,
@SerializedName("created") val created : String,
@SerializedName("modified") val modified : String,
@SerializedName("product_images") val product_images : String
)
不确定,但这里的问题可能与 json 适配器的浮点转换有关。 您可以做的是将该字段作为字符串获取,因此在转换时该值不会丢失。
@SerializedName("rating") val rating : String,
现在在您的适配器中尝试将其转换为浮点数。
holder.rate.setRating(Tablelist.get(position).rating.toFloat())
你能试试这个吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.