如何解决使用共享的首选项将等级栏值存储在警报对话框中
基本上我有一个按钮-> 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 举报,一经查实,本站将立刻删除。