Sunday, January 8, 2017

Android Listview tutorial

this is test post this is test post this is test post this is test post this is test post this is test post this is test post this is test post this is test post this is test post this is test post this is test post this is test post this is test post this is test post this is test post this is test post this is test post this is test post this is test post this is test post this is test post this is test post this is test post this is test post this is test post this is test post this is test post this is test post this is test post this is test post this is test post this is test post this is test post this is test post this is test post this is test post this is test post this is test post this is test post this is test post


at first you have to create a adapter


adapter code :
public class MyVidListAdapter extends BaseAdapter {
    private Context mContext;
    private LayoutInflater mInflater;
    private ArrayList<MyVideoList> mDataSource;
    MyVideoList myVideoListmodel=null;

    public MyVidListAdapter(Context mContext,  ArrayList<MyVideoList> mDataSource) {
        this.mContext = mContext;
        this.mDataSource = mDataSource;
        mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    private static class ViewHolder {
        public TextView titleTextView;
        public TextView subtitleTextView;
        public TextView detailTextView;
        public ImageView thumbnailImageView;
        public  ImageView vListImg;

    }

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

    @Override    public Object getItem(int position) {
        return mDataSource.get(position);
    }

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

    @Override    public View getView(int position, View convertView, ViewGroup parent) {
        myVideoListmodel = mDataSource.get(position);
        ViewHolder holder = null;
        LayoutInflater mInflater = (LayoutInflater)
                mContext.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);

        if (convertView == null){
            convertView = mInflater.inflate(R.layout.my_video_list, parent, false);
        holder = new ViewHolder();

        holder.titleTextView = (TextView) convertView.findViewById(R.id.vTittleText);
        holder.subtitleTextView = (TextView) convertView.findViewById(R.id.vChannelText);
        holder.detailTextView = (TextView) convertView.findViewById(R.id.vDurationText);
        holder.thumbnailImageView = (ImageView) convertView.findViewById(R.id.vImage);
        holder.vListImg = (ImageView)convertView.findViewById(R.id.vListImg);

        convertView.setTag(holder);
        return convertView;
    }
        else{
            holder = (ViewHolder)convertView.getTag();
        }
        myVideoListmodel = (MyVideoList)getItem(position);

        holder.titleTextView.setText(myVideoListmodel.getTittle());
        holder.subtitleTextView.setText(myVideoListmodel.getChannel());
        holder.detailTextView.setText(myVideoListmodel.getDuration());
        holder.thumbnailImageView.setImageResource(myVideoListmodel.getImgId());
        holder.vListImg.setImageResource(myVideoListmodel.getImgId1());
        return convertView;
}
}

No comments:

Post a Comment