Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass multiple array values in a Custom Adapter class for Custom List View?

I have a list view with an image icon on the left and three text views on the right in a single row. I have created the layout, but while creating the adapter class I am facing some issues. Here is the code:

import android.app.Activity; import android.widget.ArrayAdapter;  public class CustomList extends ArrayAdapter<String>{      private final Activity context;     private final String[][] listRow;     private final Integer[] imageId;      public CustomList(Activity context, String[][] listRow, Integer[] imageId){         super(context, R.layout.rowlayout, listRow);     } } 

First I created three 1D arrays for the three textviews, but in the constructor I was not able to pass them all.

So I had to create a 2D array where every row in the table would represent information about a single list view item.

But I am not able to do so. I get an error:

Cannot resolve method super(android.app.Activity, int, java.lang.String[][]) with 2D arrays

How do I solve this issue?

like image 533
Java Enthusiast Avatar asked Apr 20 '15 12:04

Java Enthusiast


1 Answers

After trying for a long time, I found the solution. I created a separate class to store the data values for each individual row and created an array of objects of the same.

Here is the sample code:

import android.app.Activity; import android.widget.ArrayAdapter;  class ListItem {     public String textview1;     public String textview2;     public String textview3;     public int imageId;      public ListItem(String t1, String t2, String t3, int imageId)     {         this.textview1 = t1;         this.textview2 = t2;         this.textview3 = t3;         this.imageId = imageId;     } }  public class CustomList extends ArrayAdapter<Object> {     private Activity context;     private ListItem listItem[];      public CustomList(Activity context, ListItem li[])     {         super(context, R.layout.rowlayout, li);         } } 
like image 142
Java Enthusiast Avatar answered Oct 12 '22 01:10

Java Enthusiast