Android Listview标题和部分月份和日期列表

Android Listview标题和部分月份和日期列表,第1张

概述我是一个新的 Android开发人员.我搜索了很多谷歌,但我 没有得到理想的结果.我也试过我的逻辑,但我没有得到它.如果有人可以帮忙解决这个问题,我会很感激. 1. My problem is that ______________ November,2012 //This is header ______________ November 12,201 我是一个新的 Android开发人员.我搜索了很多谷歌,但我
没有得到理想的结果.我也试过我的逻辑,但我没有得到它.如果有人可以帮忙解决这个问题,我会很感激.

1. My problem is that    ______________    November,2012     //This is header     ______________    November 12,2012    November 15,2012   //This List of date that contain in month    _____________    December,2012      //This is header     _____________    December 23,2012    December 30,2012    //This List of date that contain in month

我的问题是如何获取包含相同月份列表的项目列表
其中的项目如何解决这个问题?请提出一些想法.

解决方法 这是一种方法

使用Separator视图创建自定义ListVIEw ROW布局文件. (标题TextVIEw)

ListvIEw_row_with_separator.xml

<?xml version="1.0" enCoding="utf-8"?>    <linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent"    androID:orIEntation="vertical" >    <!-- List Separator TextVIEw Style - the List separator header-->   <TextVIEw                androID:ID="@+ID/textvIEw_header_separator"        androID:layout_wIDth="fill_parent"        androID:layout_height="wrap_content"        androID:textcolor="@androID:color/black"        androID:text="November,2012"        androID:visibility="gone"         />    <linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent"    androID:orIEntation="vertical" >    <TextVIEw        androID:ID="@+ID/textVIEw_row_value"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:text="November 12,2012"        androID:textAppearance="?androID:attr/textAppearanceMedium" >    </TextVIEw>    </linearLayout>    </linearLayout>

importent!确保您的列表以某种方式排序(日期)

扩展一个包含“Your_List_Item”的ArrayAddapter,并实现一个populateVIEw(Your_List_Item),如果下一个列表项与前一个列表项不相等,则显示一个分隔符.

public class Your_List_Adapter extends ArrayAdapter<Your_List_Item> {private Activity mActivity;private String mCurrentMonth = "";public Your_Adapter(Activity activity) {    super(activity,0);      mActivity = activity;}public VIEw getVIEw(int position,VIEw convertVIEw,VIEwGroup parent) {    VIEwHolder holder;    if (convertVIEw == null) {        convertVIEw = mActivity.getLayoutInflater().inflate(                R.layout.ListvIEw_row_with_separator,null);        holder = new VIEwHolder(convertVIEw);        convertVIEw.setTag(holder);    } else {        // the (List row) convertVIEw is already inflated,so we can get        // it from the Tag        holder = (VIEwHolder) convertVIEw.getTag();    }    Your_List_Item your_List_item = getItem(position);    //Check if the next List item is not equal the prevIoUs List item.    if (!mCurrentMonth.equalsIgnoreCase(your_List_item.month.toString())) {        holder.populateVIEw(your_List_item,true);        mCurrentMonth = your_List_item.date;    } else{        holder.populateVIEw(your_List_item,false);    }    return convertVIEw;}}

适配器的VIEwHolder类,如果需要,显示分隔符

class VIEwHolder { /********** DECLARES ************/private TextVIEw textVIEw_row_value;public TextVIEw textvIEw_header_separator;public VIEwHolder(final VIEw root) {    /********** INITIAliZES *************/    textvIEw_header_separator = (TextVIEw) root.findVIEwByID(R.ID.textvIEw_header_separator);    textVIEw_row_value = (TextVIEw) root.findVIEwByID(R.ID.textVIEw_row_value);}public voID populateVIEw(final Your_List_Item your_List_item,final boolean needSeparator) {    /*     *  add Separator     */    if (needSeparator) {             //set header text: November,2012         textvIEw_header_separator.setText(your_List_item.date);             textvIEw_header_separator.setVisibility(VIEw.VISIBLE);    } else {             textvIEw_header_separator.setVisibility(VIEw.GONE);    }    //set row value: November 12,2012    textVIEw_row_value.setText(your_List_item.date); }}
总结

以上是内存溢出为你收集整理的Android Listview标题和部分月份和日期列表全部内容,希望文章能够帮你解决Android Listview标题和部分月份和日期列表所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1127336.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存