I'm using firebase database and glide to access images stored in firebase storage. but when i run the code it seems to duplicate the items after the first 6. here is my database ref
ref = db.getReference().child("LOGOS");
Which in my database looks like this
{
"70s": "My FirebaseStorage https web address",
"80s": "My FirebaseStorage https web address",
"90s": "My FirebaseStorage https web address",
"COMMERCIAL": "My FirebaseStorage https web address",
"DANCE": "My FirebaseStorage https web address",
"HIPHOP": "My FirebaseStorage https web address",
"MASHUP": "My FirebaseStorage https web address",
"NEWS": "My FirebaseStorage https web address"
}
then here is my coding
ref.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
Genre_Adapter adapter;
imageUrl.clear();
for (DataSnapshot snapa : snapshot.getChildren()) {
String logo = snapa.getValue(String.class);
imageUrl.add(logo);
// I've added a Log here to see that the data returns the right values and it
// does, but when loaded in to the list view it repeats.
String key = snapa.getKey();
Log.e("KEYS", key);
these are the values returned in my log
this is what is returned when i log.e the string key
2022-08-15 11:47:08.958 19751-19751/com.p9p.radioify E/KEYS: 70S
2022-08-15 11:47:08.959 19751-19751/com.p9p.radioify E/KEYS: 80S
2022-08-15 11:47:08.959 19751-19751/com.p9p.radioify E/KEYS: 90S
2022-08-15 11:47:08.959 19751-19751/com.p9p.radioify E/KEYS: COM
2022-08-15 11:47:08.959 19751-19751/com.p9p.radioify E/KEYS: DANCE
2022-08-15 11:47:08.960 19751-19751/com.p9p.radioify E/KEYS: DRUM & BASS
2022-08-15 11:47:08.960 19751-19751/com.p9p.radioify E/KEYS: HIPHOP
2022-08-15 11:47:08.960 19751-19751/com.p9p.radioify E/KEYS: MASHUP
2022-08-15 11:47:08.960 19751-19751/com.p9p.radioify E/KEYS: NEWS
2022-08-15 11:47:08.960 19751-19751/com.p9p.radioify E/KEYS: TRANCE
2022-08-15 11:47:08.960 19751-19751/com.p9p.radioify E/KEYS: UNITEDKINGDOM
this is where i convert to an array for my adapter class
imageurl = imageUrl.toArray(new String[imageUrl.size()]);
adapter = new Genre_Adapter(getContext(), imageurl);
}#
adapter = new Genre_Adapter(getContext(), imageurl);
mlist.setAdapter(adapter);
mlist.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
genre_list_item gli = new genre_list_item();
Bundle bundle = new Bundle();
bundle.putString("Genre", btntitle.get(position));
Log.i("genre_title", btntitle.get(position));
gli.setArguments(bundle);
getActivity().getSupportFragmentManager().beginTransaction()
.replace(R.id.frame1, gli, "genre_list_item")
.addToBackStack(null).commit();
}
this is my adapter class
public Genre_Adapter(Context context,String[]logo){
this. context = context;
this.logo = logo;
}
@Override
public int getCount() {
return logo.length;
}
@Override
public Object getItem(int position) {
return logo[position];
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final View row;
if (convertView == null) {
row = LayoutInflater.from(parent.getContext()).inflate(R.layout.genre, parent, false);
imageView = row.findViewById(R.id.image);
} else {
row = convertView;
}
Glide.with(context).load(logo[position]).into(imageView);
return (row);
}
**EDIT I have tried these answers today. None of which have worked.