我确实尝试使用卡片视图中文本视图的值来更新等级栏,但是仅在加载第一张卡片时才更新。对于堆叠等级栏中的所有其他卡,第一张卡之后便会更新音符。
在刷了第一张卡后,基本评级栏没有更新。
我该怎么办?
public void getOppositeSexUsers22() {
usersDb.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
if (dataSnapshot.child("post").getValue() != null) {
if (dataSnapshot.exists() && !dataSnapshot.child("connections").child("nope").hasChild(currentUId) && !dataSnapshot.child("connections").child("yeps").hasChild(currentUId) && dataSnapshot.child("post").getValue().toString().equals(oppositeUserSex2)) {
String profileImageUrl = "default";
String oppsiteexperince = "default";
Integer score0;
Integer score1 = 0;
Integer score2 = 0;
Integer score3 = 0;
Integer score4 = 0;
if (dataSnapshot.child("industry").getValue().toString().equals(userJob)) {
score1 = 50;
}
if (dataSnapshot.child("salary").getValue().toString().equals(userSalary)) {
score2 = 15;
}
if (!dataSnapshot.child("salary").getValue().toString().equals(userSalary) && dataSnapshot.child("salary").getValue().toString().equals(userex6)) {
score2 = 15;
}
if (dataSnapshot.child("timetofill").getValue().toString().equals(userTimevacancy)) {
score3 = 15;
}
if (dataSnapshot.child("experience").getValue().toString().equals(userExperince)) {
score4 = 20;
}
if (!dataSnapshot.child("profileImageUrl").getValue().equals("default")) {
profileImageUrl = dataSnapshot.child("profileImageUrl").getValue().toString();
}
score0 = score1 + score2 + score3 + score4;
mytest = String.valueOf(score0);
cards item = new cards(dataSnapshot.getKey(), dataSnapshot.child("name").getValue().toString(), mytest, profileImageUrl);
m2.setText(mytest);
ratingBarset();
rowItems.add(item);
arrayAdapter.notifyDataSetChanged();
}
}
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onCancelled(DatabaseError databaseError) {
Toast.makeText(MainActivity.this, String.valueOf("error"), Toast.LENGTH_SHORT).show();
}
});
}
下面是评分栏方法
public void ratingBarset() {
String a = mytest;
switch (a) {
case "5":
ratingBar.setRating(Float.parseFloat("1.0"));
break;
case "10":
ratingBar.setRating(Float.parseFloat("1.5"));
break;
case "15":
ratingBar.setRating(Float.parseFloat("2.0"));
break;
case "20":
ratingBar.setRating(Float.parseFloat("2.5"));
break;
case "25":
ratingBar.setRating(Float.parseFloat("3.0"));
break;
case "30":
ratingBar.setRating(Float.parseFloat("3.5"));
break;
case "35":
ratingBar.setRating(Float.parseFloat("4.0"));
break;
case "40":
ratingBar.setRating(Float.parseFloat("4.5"));
break;
case "45":
ratingBar.setRating(Float.parseFloat("4.5"));
break;
case "50":
ratingBar.setRating(Float.parseFloat("5.0"));
break;
case "55":
ratingBar.setRating(Float.parseFloat("5.0"));
break;
case "60":
ratingBar.setRating(Float.parseFloat("5.0"));
break;
case "65":
ratingBar.setRating(Float.parseFloat("5.0"));
break;
case "70":
ratingBar.setRating(Float.parseFloat("5.0"));
break;
case "75":
ratingBar.setRating(Float.parseFloat("5.0"));
break;
case "80":
ratingBar.setRating(Float.parseFloat("5.0"));
break;
default:
ratingBar.setRating(Float.parseFloat("0.0"));
break;
}
}