Search code examples
javaandroidandroid-studioandroid-layoutcard

Display multiple elements in card-like disposition with a loop - Android


I'm fairly new with Android development so I'm just trying some concepts.

For this POC I took the first 20 values from this IMDB list => https://www.imdb.com/chart/toptv/

added them into a JSON which is inside the assets folder of my project. I have a method in my main activity to access the content of the JSON file, it goes like this:

  public void readMovies() {
    String jsonFileString = Utils.getJsonFromAssets(getApplicationContext(), "movies.json");
    Log.i("data", jsonFileString);

    Gson gson = new Gson();
    Type listUserType = new TypeToken<List<Movies>>() { }.getType();


    List<Movies> movies = gson.fromJson(jsonFileString, listUserType);
    for (int i = 0; i < movies.size(); i++) {
        Log.i("data", "> Item " + i + "\n" + movies.get(i));
    }
}

Using a textView I'm able to output all the titles (for example) in the layout, but I'd like to be able to display a view similar to the IMDB page, with an image to the left side, title on the centre and any other property on the right side.

enter image description here

How can I achieve a view like the shared URL?


Solution

  • You've to create a Listview with images and text. Attaching some resources.

    1. Checkout the answers to this Stack overflow question
    2. Check out this Youtube tutorial or this one.

    These are the ones I found which provide a code walk-through. But now you know the keywords to search for, you can find resources on your own!