问题描述
public void onChildAdded(@NonNull DataSnapshot snapshot,@Nullable String prevIoUsChildName) {
Blueweb obj4 = snapshot.getValue(Blueweb.class);
adapter.add(obj4);
}
MyAdapterCode:
public class BluewebAdapter extends ArrayAdapter<Blueweb> {
public BluewebAdapter(@NonNull Context context,int resource,List<Blueweb> bluewebList) {
super(context,resource);
}
@NonNull
@Override
public View getView(int position,@Nullable View convertView,@NonNull ViewGroup parent) {
if(convertView ==null){
convertView = ((Activity)getContext()).getLayoutInflater().inflate(R.layout.message_item,parent,false);
}
ImageView photoImageView = convertView.findViewById(R.id.photoImageView);
TextView textTextView = convertView.findViewById(R.id.textTextView);
TextView nameTextView = convertView.findViewById(R.id.nameTextView);
Blueweb obj = getItem(position);
boolean isText = obj.getimageURl()==null;
if(isText){
textTextView.setVisibility(View.VISIBLE);
photoImageView.setVisibility(View.INVISIBLE);
nameTextView.setText(obj.getText());
}
else{
textTextView.setVisibility(View.GONE);
photoImageView.setVisibility(View.VISIBLE);
Glide.with(photoImageView.getContext()).
load(obj.getimageURl()).
into(photoImageView);
}
nameTextView.setText(obj.getName());
return convertView;
}
}
解决方法
snapshot.getValue(Blueweb.class)
返回您尝试转换为Blueweb类型的字符串类型
请尝试以下代码:
String obj4 = snapshot.getValue(String.class);