Reputation: 121
I'm making an app which allows a user to search the various countries. The user can make filtered searches (such as, for example, search only countries of a specific continent, etc...). All this info (Countries and their continents are stored in my Firebase Realtime Database).
In my FilteredResults.java
fragment I want to have a variable number of ImageViews (the number of the size of a List<String>
).
This sketch I drew might help you understand it better:
Each one of this rectangles are ImageViews. This is my XML (I just have a scrollview because I don't know how to create an "array" of ImageViews...)
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/txtResultadosFiltrados"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="28dp"
android:layout_marginTop="0dp"
android:text="Resultados Filtrados"
android:textColor="#323B45"
android:textSize="24sp"
tools:layout_editor_absoluteX="16dp"
tools:layout_editor_absoluteY="28dp" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
</ScrollView>
</RelativeLayout>
Upvotes: 0
Views: 123
Reputation: 929
In order to solve your problem in an optimal way, you should use one of:
These views support so called adapters
which map between a model (in your case: List<String>
) and a list of items (in your case a list of ImageView
's).
Here you have a complete example of a simple app which loads lists of posts from the Firebase Database: https://github.com/firebase/quickstart-android/tree/master/database
This example is based on RecyclerView
s, you can find an a direct usage here:
https://github.com/firebase/quickstart-android/blob/master/database/app/src/main/java/com/google/firebase/quickstart/database/fragment/PostListFragment.java
Upvotes: 2
Reputation: 1857
Use RecyclerView
instead of ScrollView
. As keeping array of ImageView
and adding them in a ScrollView
will create a explosive headache.
Upvotes: 1