使用共享的首选项将等级栏值存储在警报对话框中

问题描述

基本上我有一个按钮-> Onclick->警报对话框出现..在该警报对话框中有一个等级栏。在该等级栏上我使用成功完成的翻新将速率值发送到服务器。但是我遇到的问题是使用共享的preference.im共享我的代码来存储该费率值:-

ratebutton.setOnClickListener {
                    val mBuild: AlertDialog.Builder = AlertDialog.Builder(this@Product_details)
                    val mView: View = layoutInflater.inflate(R.layout.ratedialog,null)

                    val ratebar =mView.findViewById(R.id.ratingBaruser) as RatingBar

                    val titleimage=mView.findViewById<TextView>(R.id.titleimage)  as TextView
                    val imagerate=mView.findViewById<ImageView>(R.id.imagerate) as ImageView
                    titleimage.setText(ygd)
                 Glide.with(getApplicationContext()).load(res?.body()!!.data.product_images.get(0).image).into(imagerate);
                  val  wmbPreference1 = PreferenceManager.getDefaultSharedPreferences(applicationContext)
                    val rating: Float = wmbPreference1.getFloat("numStars",0f)
                    ratebar.setRating(rating)
                    ratebar.onRatingBarChangeListener =
                        OnRatingBarChangeListener { ratingBar,rating1,fromUser ->
                         val   editor = wmbPreference1.edit();
                            editor.putFloat("numStars",rating);
                            editor.commit();
                            rateValue = rating1
                            Toast.makeText(this@Product_details,"" + rating1,Toast.LENGTH_SHORT).show()
                        }

                    val btnSubmit =
                        mView.findViewById(R.id.btnSubRating) as Button
                    btnSubmit.setOnClickListener(object : View.OnClickListener {
                        override  fun onClick(v: View?) {
                            RetrofitClient.instancetable.setRating(id,rateValue)
                                .enqueue(object : Callback<Rate_Response> {
                                    override fun onFailure(call: Call<Rate_Response>,t: Throwable) {
                                        Log.d("res","" + t)
                                    }
                                    override fun onResponse(
                                        call: Call<Rate_Response>,response: Response<Rate_Response>
                                    ) {
                                        var res = response
                                        if (res.isSuccessful) {
                                            Toast.makeText(
                                                applicationContext,res.body()?.user_msg,Toast.LENGTH_LONG
                                            ).show()
                                        }
                                        else{
                                            try {
                                                val jObjError =
                                                    JSONObject(response.errorBody()!!.string())
                                                Toast.makeText(
                                                    applicationContext,jObjError.getString("message")+jObjError.getString("user_msg"),Toast.LENGTH_LONG
                                                ).show()
                                            } catch (e: Exception) {
                                                Toast.makeText(applicationContext,e.message,Toast.LENGTH_LONG).show()
                                                Log.e("errorrr",e.message)
                                            }
                                        }
                                    }
                                })
                            Toast.makeText(this@Product_details,"" + rateValue,Toast.LENGTH_SHORT).show()
                        }
                    })

                    mBuild.setView(mView)
                    val dialog: AlertDialog = mBuild.create()
                    dialog.show()
                }

以上代码输出:-

当我再次单击该按钮时,我看不到用户完成的先前费率值

我需要帮助,在此先感谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...