How to add Header in ListView at specific location and create custom view for list item

前端 未结 3 1966
臣服心动
臣服心动 2021-01-20 14:51

i am again here with one issue i want to crate a custom view of list item with imageview and textview\'s and also i need to add header\'s on specific positions. i never use

3条回答
  •  爱一瞬间的悲伤
    2021-01-20 15:16

    I understood it a little bit. You should add more attribute like header in your model.

    If your header = true and in your adapter class, then you have to inflate the layout header.xml. Otherwise, if header = false, then you should inflate your xml file i.e. (TextView,ImageView) as normal.

    Here separator in my code is the same as your header

    @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
                // TODO Auto-generated method stub
    
                final recordModel model = records.get(position);
                ViewHolder holder;
                 convertView = null;
                holder = new ViewHolder();
                if(records.get(position).getSeparator()==0){
                        convertView = inflater.inflate(R.layout.record_row, null);
                        convertView.setTag(holder);
                        holder.imageView = (ImageView) convertView
                                        .findViewById(R.id.iconCallType);
                        holder.title = (TextView) convertView.findViewById(R.id.title);
                        holder.note = (TextView) convertView.findViewById(R.id.note);
                        holder.checkBox = (CheckBox) convertView.findViewById(R.id.check_box);
                       ..........................
                }else if(records.get(position).getSeparator()==1){
                        convertView = inflater.inflate(R.layout.separator, null);
                        convertView.setTag(holder);
                        holder.title = (TextView) convertView.findViewById(R.id.textSeparator);
                        holder.title.setText(records.get(position).getCallDay());
                }
    
    
                return convertView;
        }
    

提交回复
热议问题