Android OnRatingBar与OnRatingBar之间的差异发生了变化
我的android应用程序中有一个评级条,它位于自定义适配器中。我已经设置了ratingbar来监听更改,并在该更改上通过cient/server架构更新数据库。然后在主/详细视图中使用自定义适配器。问题是,每次我点击左侧列表项加载详细信息页面时,它都会更新评级栏。这不是我想要的。我只想在单击评级栏后更新它,而不是每次使用适配器时 是否有方法仅在单击事件而不更改它时触发事件。当前的onratingbarchanged和我认为应该做的onratingbarclicked之间有很大区别吗 我的代码如下:Android OnRatingBar与OnRatingBar之间的差异发生了变化,android,onclicklistener,ratingbar,Android,Onclicklistener,Ratingbar,我的android应用程序中有一个评级条,它位于自定义适配器中。我已经设置了ratingbar来监听更改,并在该更改上通过cient/server架构更新数据库。然后在主/详细视图中使用自定义适配器。问题是,每次我点击左侧列表项加载详细信息页面时,它都会更新评级栏。这不是我想要的。我只想在单击评级栏后更新它,而不是每次使用适配器时 是否有方法仅在单击事件而不更改它时触发事件。当前的onratingbarchanged和我认为应该做的onratingbarclicked之间有很大区别吗 我的代码如
//Should this rather be setOnClickListener()???
ratingBar.setOnRatingBarChangeListener(new OnRatingBarChangeListener()
{
public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser)
{
questions.get(position).TotalRating = rating;
String newRating = "" + rating;
ratingBar.setRating(rating);
Toast.makeText(getContext(),
"Rating set to: " + rating + " for the position: " + position, Toast.LENGTH_SHORT).show();
String question = questions.get(position).Question;
//Create XML with both position/question to send to doAsyncTask
serverUpdateRating update = new serverUpdateRating();
Document doc;
try
{
//Create an XML document with question from the selected position as well as the new rating
doc = x.createDoc();
Element tutor = doc.createElement("Update");
tutor.appendChild(x.UpdateRating(doc, newRating, question));
doc.appendChild(tutor);
//Create a string
String s = x.getStringFromDocument(doc);
String result = update.execute(s).get();
//return either true (updated correctly) or false (problem)
if (result.equals("true"))
{
Toast.makeText(getContext(),
"Rating successfully updated", Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(getContext(),
"Rating update unsuccessful", Toast.LENGTH_LONG).show();
}
}
catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
我不知道是否有解决办法,但如果有,我将不胜感激 您可以在onRatingChanged中使用fromUser
:
[…]如果评级更改是由用户触摸启动的,则来自user True
手势或箭头键/水平履带铃移动