title: How to populate listview from a class that has arraylist of string member?
body: <p>I'm creating an app where there is a listview of apps activity, each app has an on click listener that opens an activity with app infotmation.</p>
  
  <p>This is the Application class:</p>
  
  <pre><code>public class Application {
  
      private String title;
      private String imageUrl;
      private ArrayList&lt;String&gt; appVersions;
  
  
      public Application(String title, String imageUrl, ArrayList&lt;String&gt; appVersions) {
          this.title = imageName;
          this.imageUrl = imageUrl;
          this.appVersions = appVersions;
      }
  
  
      public String getTitle() {
          return title;
      }
  
      public void setTitle(String imageName) {
          this.title = imageName;
      }
  
      public String getImageUrl() {
          return imageUrl;
      }
  
      public void setImageUrl(String imageUrl) {
          this.imageUrl = imageUrl;
      }
  
      public ArrayList&lt;String&gt; getAppVersions() {
          return appVersions;
      }
  
      public void setAppVersions(ArrayList&lt;String&gt; appVersions) {
          this.appVersions = appVersions;
      }
  }
  </code></pre>
  
  <p>and this is the ApplicationVersionAdapter class:</p>
  
  <pre><code>import java.util.ArrayList;
  
  public class ApplicationVersionAdapter extends ArrayAdapter&lt;Application&gt; {
  
      private static final String TAG = "ApplicationVersionAdapt";
      private Context mContext;
      private int mResource;
  
      public ApplicationVersionAdapter(@NonNull Context context, int resource, @NonNull ArrayList&lt;Application&gt; objects) {
          super(context, resource, objects);
          this.mContext = context;
          this.mResource = resource;
      }
  
      @NonNull
      @Override
      public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
          String appVersion = getItem(position).getAppVersions().get(position);
          // String appVersion = getItem(position).getImageName();
          Log.d("Application version: ", getItem(position).getAppVersions().get(position));
  
  
          LayoutInflater inflater = LayoutInflater.from(mContext);
          convertView = inflater.inflate(mResource, parent, false);
          TextView tvAppVersion = convertView.findViewById(R.id.app_version);
          tvAppVersion.setText(appVersion);
  
          return convertView;
      }
  }
  </code></pre>
  
  <p>and in gallery activity I set the adapter:</p>
  
  <pre><code>ApplicationVersionAdapter adapter = new ApplicationVersionAdapter(this, 
  R.layout.layout_appversion, list);
  appVersionsList.setAdapter(adapter);
  </code></pre>
  
  <p>Each application object has versions:</p>
  
  <p>Application 1:
  name: app1
  image: imageUrl
  versions: v 1.0
            v 1.1
            v 1.2</p>
  
  <p>Gallery layout:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical" android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:weightSum="100"&gt;
  
      &lt;ImageView
          android:layout_width="match_parent"
          android:layout_height="0dp"
          android:layout_weight="50"
          android:id="@+id/image"
          android:scaleType="centerCrop"
          android:src="@mipmap/ic_launcher_round"/&gt;
  
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/image_description"
          android:layout_marginLeft="10dp"
          android:layout_marginTop="10dp"
          android:text="Canada"
          android:textColor="#000"/&gt;
  
      &lt;ListView
          android:layout_width="match_parent"
          android:layout_height="0dp"
          android:layout_weight="40"
          android:id="@+id/app_versions"&gt;
  
      &lt;/ListView&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>how to populate the list of application versions in the gallery activity?</p>
  
  <p><strong>Update</strong>
  This is my RecyclerViewAdapter for the list of applications in main activity, I'm using images to fill the list not the application class but I will put the RecyclerViewAdapter to see the onClick listener:</p>
  
  <pre><code>import android.content.Context;
  import android.content.Intent;
  import android.support.annotation.NonNull;
  import android.support.v7.widget.RecyclerView;
  import android.util.Log;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.RelativeLayout;
  import android.widget.TextView;
  import android.widget.Toast;
  
  import com.bumptech.glide.Glide;
  
  import java.util.ArrayList;
  
  import de.hdodenhof.circleimageview.CircleImageView;
  
  public class RecyclerViewAdapter extends RecyclerView.Adapter&lt;RecyclerViewAdapter.ViewHolder&gt;{
  
      private static final String TAG = "RecyclerViewAdapter";
      private ArrayList&lt;String&gt; mImageNames = new ArrayList&lt;&gt;();
      private ArrayList&lt;String&gt; mImages = new ArrayList&lt;&gt;();
      private Context mContext;
  
      public RecyclerViewAdapter(Context mContext, ArrayList&lt;String&gt; mImageNames, ArrayList&lt;String&gt; mImages) {
          this.mImageNames = mImageNames;
          this.mImages = mImages;
          this.mContext = mContext;
      }
  
      @NonNull
      @Override
      public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
          View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_listitem, parent, false);
          ViewHolder holder = new ViewHolder(view);
          return holder;
      }
  
      @Override
      public void onBindViewHolder(@NonNull ViewHolder holder, final int position) {
          Log.d(TAG, "onBindViewHolder: called.");
          Glide.with(mContext)
                  .asBitmap()
                  .load(mImages.get(position))
                  .into(holder.image);
          holder.title.setText(mImageNames.get(position));
          holder.parentLayout.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  Log.d(TAG, "onClick: clicked on: " + mImageNames.get(position));
                  // Toast.makeText(mContext, mImageNames.get(position), Toast.LENGTH_SHORT).show();
                  Intent intent = new Intent(mContext, GalleryActivity.class);
                  intent.putExtra("image_name", mImageNames.get(position));
                  intent.putExtra("image_url", mImages.get(position));
                  mContext.startActivity(intent);
              }
          });
  
      }
  
      @Override
      public int getItemCount() {
          return mImageNames.size();
      }
  
      public class ViewHolder extends RecyclerView.ViewHolder{
  
          CircleImageView image;
          TextView title;
          RelativeLayout parentLayout;
  
          public ViewHolder(View itemView) {
              super(itemView);
              image = itemView.findViewById(R.id.image);
              title = itemView.findViewById(R.id.title);
              parentLayout = itemView.findViewById(R.id.parent_layout);
          }
      }
  }
  </code></pre>
  
  <p><strong>Update</strong>
  Gallery activity:</p>
  
  <pre><code>public class GalleryActivity extends AppCompatActivity {
      private static final String TAG = "GalleryActivity";
      ListView appVersionsList;
  
      @Override
      protected void onCreate(@Nullable Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_gallery);
          appVersionsList = findViewById(R.id.app_versions);
          Log.d(TAG, "onCreate: started.");
  
          getIncommingIntent();
      }
  
      private void getIncommingIntent() {
          Log.d(TAG, "getIncommingIntent: checking for the incomming intents");
          if(getIntent().hasExtra("image_url") &amp;&amp; getIntent().hasExtra("image_name")) {
              String imageUrl = getIntent().getStringExtra("image_url");
              String imageName = getIntent().getStringExtra("image_name");
              setImage(imageUrl, imageName);
          }
      }
  
      public void setImage(String imageUrl, String imageName) {
          Log.d(TAG, "setImage: setting the image and name to widgets.");
  
          TextView name = findViewById(R.id.image_description);
          name.setText(imageName);
  
          ImageView image = findViewById(R.id.image);
          Glide.with(this)
                  .asBitmap()
                  .load(imageUrl)
                  .into(image);
  }
  }
  </code></pre>