Примечание: английский не мой родной язык.Извините за ошибку в моем тексте.
Доброе утро всем.
Я заполняю cardview
данными из firebase realtime database
.Я поймал пример с рабочим кодом изображения и имени.Но я не могу заполнить рейтинг из firebase
данных.Ниже приведены мои классы:
карты XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="40sp"
android:paddingRight="40sp"
android:paddingTop="30sp"
android:paddingBottom="200sp"
android:outlineProvider="bounds"
android:clipToPadding="false">
<android.support.v7.widget.CardView
android:layout_width="wrap_content"
android:layout_height="400dp"
app:cardCornerRadius="4dp"
android:elevation="2dp"
android:id="@+id/cardView">
<LinearLayout
android:id="@+id/layout1"
android:layout_width="300dp"
android:layout_height="402dp"
android:layout_gravity="center"
android:orientation="vertical">
<LinearLayout
android:id="@+id/layout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
>
<ImageView
android:id="@+id/image"
android:layout_width="250dp"
android:layout_height="300dp"
android:layout_gravity="center" />
</LinearLayout>
<LinearLayout
android:id="@+id/layout3"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center|left"
android:paddingLeft="20sp"
android:textColor="@android:color/black"
android:textSize="30sp"
tools:text="Nome do Técnico" />
</LinearLayout>
<LinearLayout
android:id="@+id/layout4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<RatingBar
android:id="@+id/ratingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_gravity="center|bottom"
android:numStars="5"
android:stepSize="0.1"
android:layout_below="@+id/layout3"/>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
Модель карты
public class cards {
private String userId;
private String name;
private String profileImageUrl;
private String ratingBar;
public cards (String userId, String name, String profileImageUrl, String ratingBar){
this.usuarioId = userId;
this.name = name;
this.profileImageUrl = profileImageUrl;
this.ratingBar = ratingBar;
}
public String getUserId(){
return userId;
}
public void setUserId(String userId){
this.userId = userId;
}
public String getName(){
return name;
}
public void setName(String name){
this.name = name;
}
public String getProfileImageUrl() {
return profileImageUrl;
}
public void setProfileImageUrl(String profileImageUrl){
this.profileImageUrl = profileImageUrl;
}
public String getRatingBar() {
return ratingBar;
}
public void setRatingBar(String ratingBar) {
this.ratingBar = ratingBar;
}
}
Адаптер
public class arrayAdapter extends ArrayAdapter<cards> {
Context context;
public arrayAdapter (Context context, int resourceId, List<cards> itens){
super(context, resourceId, itens);
}
public View getView (int position, View convertView, ViewGroup parent){
cards card_item = getItem(position);
if (convertView == null){
convertView = LayoutInflater.from(getContext()).inflate(R.layout.item, parent, false);
}
TextView name = (TextView) convertView.findViewById(R.id.name);
ImageView image = (ImageView) convertView.findViewById(R.id.image);
RatingBar ratingBar = (RatingBar) convertView.findViewById(R.id.ratingBar);
name.setText(card_item.getName());
card_item.getRatingBar();
ratingBar.setRating(Float.parseFloat(card_item.getRatingBar()));
switch (card_item.getProfileImageUrl()){
case "default":
Glide.with(convertView.getContext()).load(R.drawable.icone_imagem_perfil_padrao).into(image);
break;
default:
Glide.clear(image);
Glide.with(convertView.getContext()).load(card_item.getProfileImageUrl()).into(image);
break;
}
return convertView;
}
}
Метод просмотра карты:
public class CardActivity extends AppCompatActivity {
private cards cards_data [];
private br.edu.iftm.getservicer.Cards.arrayAdapter arrayAdapter;
//[...]
private String userSearched;
private void getUserProfession() {
Intent intent = getIntent();
Bundle bundle = intent.getExtras();
userSearched= bundle.getString("userSearched");
usersDb.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
if (dataSnapshot.child("profession").getValue()!=null){
if (dataSnapshot.exists() && !dataSnapshot.child("conexoes").child("nope").hasChild(usuarioAtualId) && !dataSnapshot.child("conexoes").child("yeps").hasChild(usuarioAtualId) &&
dataSnapshot.child("profession").getValue().toString().equals(userSearched) && !dataSnapshot.getKey().equals(currentUserId)){
String profileImageUrl = "default";
if (dataSnapshot.child("imagePerfilUrl").getValue().equals("default")){
profileImageUrl = dataSnapshot.child("imagePerfilUrl").getValue().toString();
}
String rate = "";
for (DataSnapshot child : dataSnapshot.child("rating").getChildren()){
rate = dataSnapshot.child("rating").getValue().toString();
}
cards item = new cards(dataSnapshot.getKey(), dataSnapshot.child("name").getValue().toString(), profileImageUrl, rate);
rowItens.add(item);
arrayAdapter.notifyDataSetChanged();
}
}
}
@Override
public void onChildChanged(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
}
@Override
public void onChildRemoved(@NonNull DataSnapshot dataSnapshot) {
}
@Override
public void onChildMoved(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
//[...]
}
Я считаю, что проблема здесь (в классе адаптеров):
ratingBar.setRating(Float.parseFloat(card_item.getRatingBar()));
Я не знаю, как установить ratingBar
.У кого-нибудь есть предложения?Спасибо.