Android ListView带有节的页眉和页脚? [英] Android ListView with section headers and footers?

查看:78
本文介绍了Android ListView带有节的页眉和页脚?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建自定义列表,以通过按数据类型对我设法获取每个节标题的数据进行分组来为每一行填充不同的数据,但是我也想为每个节添加页脚.我不知道如何执行

I want create the custom list to inflate the different data for each row by grouping the data I managed to get each section headers by the type of Data but I want to add the footer for each section as well. I don't know how to execute it

我试图通过getitemviewtype()返回节的页脚,但是必须以每种类型返回它,所以不知道如何执行

I tried to return the section footer by getitemviewtype() but it has to be return in everyitem type so don't know how to execute it

public override View GetView(int position, View convertView, ViewGroup parent)
    {
        programTabAllItemHolder programTabAllItemHolder;
        View view = convertView;
        if (view == null)
        {
            programTabAllItemHolder = new programTabAllItemHolder();
            if (GetItemViewType(position) == 0)
            {
                view = LayoutInflater.From(context).Inflate(Resource.Layout.FTSProgramItemLayout, parent, false);
                programTabAllItemHolder.searchprogramdate = view.FindViewById<TextView>(Resource.Id.searchdate);
                programTabAllItemHolder.searchprogramtime = view.FindViewById<TextView>(Resource.Id.searchtime);
                programTabAllItemHolder.searchProgramTitle = view.FindViewById<TextView>(Resource.Id.searchprogramtitle);
                programTabAllItemHolder.linearsearchdatetime = view.FindViewById<RelativeLayout>(Resource.Id.linearsearchdatetime);
                programTabAllItemHolder.programseparator = view.FindViewById<View>(Resource.Id.programline);
                programTabAllItemHolder.searchprogramresults = view.FindViewById<TextView>(Resource.Id.searchprogramresults);

            }
            else if (GetItemViewType(position) == 1)
            {
                view = LayoutInflater.From(context).Inflate(Resource.Layout.FTSParticipantItemLayout, parent, false);
                programTabAllItemHolder.initialsView = view.FindViewById<TextView>(Resource.Id.searchparticipantinitialsView);
                programTabAllItemHolder.Listimageview = view.FindViewById<ImageView>(Resource.Id.searchparticipantlistimageView);
                programTabAllItemHolder.searchParticipantTitle = view.FindViewById<TextView>(Resource.Id.searchparticipanttitle);
                programTabAllItemHolder.searchparticipantresults = view.FindViewById<TextView>(Resource.Id.searchparticipantresults);
            }
            else if (GetItemViewType(position) == 2)
            {
                view = LayoutInflater.From(context).Inflate(Resource.Layout.FTSInformationItemLayout, parent, false);
                programTabAllItemHolder.searchinformationlistimageView = view.FindViewById<ImageView>(Resource.Id.searchinformationlistimageView);
                programTabAllItemHolder.searchinformationtitle = view.FindViewById<TextView>(Resource.Id.searchinformationtitle);
                programTabAllItemHolder.searchinformationresults = view.FindViewById<TextView>(Resource.Id.searchinformationresults);

            }

            view = LayoutInflater.From(context).Inflate(Resource.Layout.SearchFooterView, parent, false);
            programTabAllItemHolder.searchfooterview = view.FindViewById<LinearLayout>(Resource.Id.ftsfooterview);


            view.Tag = programTabAllItemHolder;
        }
        else
        {
            programTabAllItemHolder = view.Tag as programTabAllItemHolder;
        }

        if (GetItemViewType(position) == 0)
        {
            // setColorsforprogram
            SetViewStyleforProgram(programTabAllItemHolder);
            programTabAllItemHolder.searchProgramTitle.Text = programVTs[position].Title;
            programTabAllItemHolder.searchprogramdate.Text = programVTs[position].StartDate.ToString("dd MMM");
            programTabAllItemHolder.searchprogramtime.Text = programVTs[position].StartDate.ToString("hh:mm tt");
        }


        // participant view
        else if (GetItemViewType(position) == 1)
        {
            programTabAllItemHolder.searchParticipantTitle.Text = programVTs[position].FirstName + programVTs[position].LastName;
            //If profile icon is missing then show initials of First Name and Last Name ahead
            if (string.IsNullOrEmpty(programVTs[position].IconUrl))
            {
                programTabAllItemHolder.Listimageview.Visibility = ViewStates.Gone;
                programTabAllItemHolder.initialsView.Visibility = ViewStates.Visible;
                programTabAllItemHolder.initialsView.Text = Utils.getUserFirstandLastChar(programVTs[position].FirstName, programVTs[position].LastName);
                programTabAllItemHolder.initialsView.SetTextColor(Color.ParseColor(Utils.topNavForegroundColor));

                //Round background image of initials
                GradientDrawable initialsShape = new GradientDrawable();
                initialsShape.SetShape(ShapeType.Oval);
                initialsShape.SetCornerRadius(100f);
                initialsShape.SetColor(Color.ParseColor(Utils.topNavBackgroundColor));
                initialsShape.SetStroke(1, Color.ParseColor(Utils.topNavBackgroundColor));

                //Invert the colors if theme is light
                if (!Util.IsColorDark(Color.ParseColor(Utils.topNavBackgroundColor)))
                {
                    initialsShape.SetColor(Color.ParseColor(Utils.topNavForegroundColor));
                    initialsShape.SetStroke(1, Color.ParseColor(Utils.topNavForegroundColor));
                    programTabAllItemHolder.initialsView.SetTextColor(Color.ParseColor(Utils.topNavBackgroundColor));
                }

                programTabAllItemHolder.initialsView.SetBackgroundDrawable(initialsShape);
            }
            else
            {
                programTabAllItemHolder.initialsView.Visibility = ViewStates.Gone;
                MyApp.picassoWithCache.Load(programVTs[position].IconUrl).Into(programTabAllItemHolder.Listimageview);
            }
            //int check = position + 1;
            //if ( check%3 == 0)
            //{
            //    programTabAllItemHolder.seachparticipantsshowmore.Visibility = ViewStates.Visible;
            //}

        }
        else if (GetItemViewType(position) == 2)
        {
            programTabAllItemHolder.searchinformationtitle.Text = programVTs[position].Title;
            if (string.IsNullOrEmpty(programVTs[position].IconUrl))
            {
                programTabAllItemHolder.searchinformationlistimageView.SetImageResource(Resource.Drawable.linked_info_default_icon);
            }
            else
            {
                MyApp.picassoWithCache.Load(programVTs[position].IconUrl).Into(programTabAllItemHolder.searchinformationlistimageView);
            }

        }



        return view;
    }

推荐答案

您可以创建自定义视图,然后对其进行充气然后像这样使用:

You can create a custom view, inflate it then can use like this:

View headerView = getLayoutInflater().inflate(R.layout.listview_header, null);
listView.addHeaderView(headerView);

有关更多信息,您可以检查此链接

For more information, you can check this link

这篇关于Android ListView带有节的页眉和页脚?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆