且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何添加页眉中的ListView在特定的位置,并创建列表项自定义视图

更新时间:2023-10-15 08:11:04

我理解这一点。你应该增加类似在模型中的头多个属性。

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

如果你的 = 真正,并在适配器类,则有膨胀的布局 header.xml 。否则,如果 = ,那么你应该夸大你的XML文件,即(的TextView 的ImageView )为正常。

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.

下面分隔符在我的code是一样的

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;
    }