0

I have tried this below code but its not working properly as I required.

My required is listing movies date wise so the object is like

MovieDate{
    date 
    counter
    List<Movies> mlist;
}

Now using BaseAdapter I tried display movies date wise as below

public class MovieAdapter extends BaseAdapter {

    private LayoutInflater inflater;
    private LoadImages loadImages;
    private List<MovieMonth> list;

    public MovieAdapter(Activity context, List<MovieMonth> list) {
        super(context,list);
        this.inflater = LayoutInflater.from(context);
        loadImages = new LoadImages(context);
        this.list = list;
    }

    private class Viewholder {
        TextView txtDate;
        TextView txtCounter;
        private LinearLayout row;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Viewholder mViewholder;
        MovieMonth mm = list.get(position);
        if (convertView == null) {

            convertView = inflater.inflate(R.layout.row, null);

            mViewholder = new Viewholder();
            mViewholder.row = (LinearLayout) convertView.findViewById(R.id.columnContainer);
            mViewholder.txtDate = (TextView) convertView.findViewById(R.id.txtDate);
            mViewholder.txtCounter = (TextView) convertView.findViewById(R.id.txtCounter);

            for (Movie movie : mm.movieList) {
                mViewholder.row.addView(initItemView(movie));
            }
            convertView.setTag(mViewholder);
        }else{
            mViewholder = (Viewholder) convertView.getTag();
        }

        mViewholder.txtDate.setText(mm.releaseDate);
        mViewholder.txtCounter.setText(mm.counter);

        return convertView;

    }

    protected View initItemView(Movie movie) {
        View v = inflater.inflate(R.layout.item, null);
        ImageView img = (ImageView) v.findViewById(R.id.imgView);
img.setImageResource(movie.image);

        return v;
    }


    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 1;
    }
}

Now the issue: (display as below for view time)

  • 1 row with 1 view ok

  • 2 rows with 10 views ok

  • 3 rows with 4 view not ok:
    It's displaying 1 row with 1 view instead of 4 views

and whenever I scroll the list its dynamic view not persist for row.

Your suggestion will be appreciated, thanks.

yennsarah
  • 5,467
  • 2
  • 27
  • 48
Pratik
  • 30,639
  • 18
  • 84
  • 159
  • Can you share screenshot that how do you want to achieve ? – Piyush Dec 04 '15 at 14:19
  • Your code looks OK, have you checked if your list isnt wrong? that should create a row and add a imageView for each movie in movielist, are you sure that position 3 has a list with 4 items? – Nanoc Dec 04 '15 at 15:13

0 Answers0