0

UPDATED CODE after Niv's answer:

Here's my Adapter method:

public class PostsListAdapter extends ArrayAdapter<String> {

/**
 * ViewHolder class for layout.<br />
 * <br />
 */
private static class ViewHolder {
    public final RelativeLayout rootView;
    public final TextView postUname;
    public final TextView postText;
    public final ImageView postPlatform;
    public final ImageView postImage;
    public final VideoView postVideo;

    private ViewHolder(RelativeLayout rootView, TextView postUname, TextView postText, ImageView postPlatform, ImageView postImage, VideoView postVideo) {
        this.rootView = rootView;
        this.postUname = postUname;
        this.postText = postText;
        this.postPlatform = postPlatform;
        this.postImage = postImage;
        this.postVideo = postVideo;
    }

    public static ViewHolder create(RelativeLayout rootView) {
        TextView postUname = (TextView)rootView.findViewById( R.id.post_uname );
        TextView postText = (TextView)rootView.findViewById( R.id.post_text );
        ImageView postPlatform = (ImageView)rootView.findViewById( R.id.post_platform );
        ImageView postImage = (ImageView)rootView.findViewById( R.id.post_image );
        VideoView postVideo = (VideoView)rootView.findViewById( R.id.post_video );
        return new ViewHolder( rootView, postUname, postText, postPlatform, postImage, postVideo );
    }
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    final ViewHolder vh;
    if ( convertView == null ) {
        View view = mInflater.inflate( R.layout.post_list, parent, false );
        vh = ViewHolder.create( (RelativeLayout)view );
        view.setTag( vh );
    } else {
        vh = (ViewHolder)convertView.getTag();
    }

    Object item = getItem( position );

    Log.d("Text", item.toString());
    vh.postText.setText(item.toString());

    return vh.rootView;
}

private LayoutInflater mInflater;

// Constructors
public PostsListAdapter(Context context, ArrayList<String> objects) {
    super(context, 0, objects);
    this.mInflater = LayoutInflater.from( context );
}

}

Now, the question is, how do I pass multiple arraylists, like I have eight arrays from which I have to populate the list. Like, for every item, I have to get eight items to show for that item, I have those eight arraylists sorted to keep a one-to-one correspondence.

Any idea how to handle multiple arraylists?

4
  • RecyclerView is the way Commented Jul 29, 2015 at 11:08
  • What if I want to save images once they're showed in the view too? Commented Jul 29, 2015 at 11:11
  • Use view holder pattern for your adapter Commented Jul 29, 2015 at 11:13
  • Please check this link for ListView/ Commented Jul 29, 2015 at 11:31

2 Answers 2

1

Try This Code. A sample Adapter

public class ListAdapter extends ArrayAdapter {

private static class ViewHolder {
    public final FrameLayout rootView;
    public final ImageView imHotelProfile;


    private ViewHolder(FrameLayout rootView, ImageView imHotelProfile) {
        this.rootView = rootView;
        this.imHotelProfile = imHotelProfile;

    }

    public static ViewHolder create(FrameLayout rootView) {
        ImageView imHotelProfile = (ImageView)rootView.findViewById( R.id.im_hotel_profile );
        ImageView imLike = (ImageView)rootView.findViewById( R.id.im_like );

        return new ViewHolder( rootView, imHotelProfile);
    }
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    final ViewHolder vh;
    if ( convertView == null ) {
        View view = mInflater.inflate( R.layout.list_adapter, parent, false );
        vh = ViewHolder.create((FrameLayout) view);
        view.setTag( vh );
    } else {
        vh = (ViewHolder)convertView.getTag();
    }

    GsonObj item = getItem( position );

    // TODOBind your data to the views here
    // fill data

    return vh.rootView;
}

private LayoutInflater mInflater;

// Constructors
public ListAdapter(Context context, List<GsonObj> objects) {
    super(context, 0, objects);
    this.mInflater = LayoutInflater.from(context);
}
public ListAdapter(Context context, GsonObj[] objects) {
    super(context, 0, objects);
    this.mInflater = LayoutInflater.from(context);
}

}

Sign up to request clarification or add additional context in comments.

9 Comments

I have a RelativeLayout. Does it matter? How much? @Niv
No change it to RelativeLayout.
But I already have a RelativeLayout. Should I change it to FrameLayout or RelativeLayout?
you can use relative layout itself
Change the last 2 constructors(ListAdapter) according to your number of arrays
|
0

Don't understand fully your question, but you can pass List parameters like this

List<List<String>> datalist = new Arraylist<>();

or

List of object list that contains String list

Hope, this will help you

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.