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

前端 未结 3 1931
臣服心动
臣服心动 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;
        }
    
    0 讨论(0)
  • 2021-01-20 15:17

    We do have a lot of amazing tutorials for the same, check some examples below:-

    1. Android Section List

    2. Android Amazing ListView

    Do let us know, if you have to deal anu issue while doing it or have to go for any specific requirements to complete it.

    0 讨论(0)
  • 2021-01-20 15:23

    You can add your own Header at any specific position using getItemViewType() and getViewTypeCount(). Here is a nice blog that explain everything about using these methods.

    0 讨论(0)
提交回复
热议问题