0

I am trying to make a listview with images and text, side by side, for every user except the current user (i.e. user of the device).

I have the JSON structure like following:

|
 --- users
 |
 |
  --- uid1
 |  |
 |   -- uid1
 |  |
 |   -- name
 |  |
 |   -- imageURL
 |  |
     -- status
    |
     -- email
    |
     -- line
 |
 |
  --- uid2

This is my adapter class:

public class MyAdapter extends ArrayAdapter<OtherUsers> {

    private Activity context;
    private int resource;
    private List<OtherUsers> list;

    public DayAdapter(@NonNull Activity context, int resource, List<OtherUsers> objects) {
        super(context, resource, objects);

        this.context = context;
        this.resource = resource;
        this.list = objects;

    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        // I am not able to figure out this part
    }


}

OtherUsers class

public class OtherUsers {

    private String line;
    private String imageURL;

    public OtherUsers(String line, String imageURL){

        this.line = line;
        this.imageURL = imageURL;

    }

    public OtherUsers(){

    }

    public String getLine(){
        return line;
    }

    public String getImageURL(){
        return imageURL;
    }

    public void setLinee(String line){
        this.line = line;
    }

    public void setImageURL(String imageURL){
        this.imageURL = imageURL;
    }


}

My list view has XML code like this:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:background="@drawable/back2"
    android:layout_width="match_parent"
    android:padding="15dp"
    android:layout_height="match_parent">


        <ImageView
            android:layout_width="80dp"
            android:id="@+id/image"
            android:layout_height="80dp"
            android:layout_weight="0.11"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/dlne"
            android:layout_alignParentTop="true"
            android:layout_toEndOf="@+id/image"
            android:layout_toRightOf="@+id/image"
            android:textColor="#333"
            android:textSize="22sp"
            android:textStyle="bold"/>

        <ListView
            android:id="@+id/listView1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">

        </ListView>


    <android.support.design.widget.FloatingActionButton
        android:id="@+id/button1"
        android:elevation="10dp"
        app:fabSize="normal"
        android:scaleType="fitXY"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentBottom="true"
        android:src="@drawable/profile"
        android:layout_alignParentEnd="true" />

</RelativeLayout>

I am not stuck at getting the data. I can retrieve the data from Firebase, I am not able to understand how can I populate the listview with images and lines.

I would appreciate if someone can help me in this.

  • Something like that https://stackoverflow.com/questions/6958279/how-to-use-a-custom-arrayadapter-in-a-separate-class – Access Denied Nov 11 '18 at 07:55
  • 2
    Take a look at the following article: https://www.androidinterview.com/android-custom-listview-with-image-and-text-using-arrayadapter/ – Access Denied Nov 11 '18 at 07:57
  • Check also **[this](https://stackoverflow.com/questions/48622480/showing-firebase-data-in-listview)** out. – Alex Mamo Nov 12 '18 at 19:16

0 Answers0