在列表之间添加 listView header
Add listView header between list
这是我的列表视图
我想在 2016-02-02
之上添加二月 header,在 2016-01-31
中添加一月。是否可以?
在android中叫做ExpandableListView
你可以试试这个教程:
http://www.androidhive.info/2013/07/android-expandable-list-view-tutorial/
它还有一个示例可供下载。
是的,您可以通过 return在适配器 class 的 getView() 方法中创建不同的视图来实现。在您传递给适配器的主列表中,您可以添加一个分隔项,一个字符串,或者您持有所有这些数据,我假设一个自定义 class,您知道它是为了显示月份标题.您可以快速检查您的 getView() 方法和 return 显示月份的不同视图..
在您的 getView() 方法中,您可以这样做...
@Override
public View getView(final int position, View convertView, ViewGroup parent){
LayoutInflater mInflator = LayoutInflater.from(getContext());
View customView = mInflator.inflate(R.layout.times_layout, parent, false);
Time temp = getItem(position);
//Check to see if the time is supposed to be a header
//This is where you check to see if it meant to be a section header
if(temp.getDate.equals("HEADER")){
//Header, return section view instead of normal view
View sectionHeader = mInflator.inflate(R.layout.layout_list_divider, parent, false);
TextView txt_Section = (TextView) sectionHeader.findViewById(R.id.txt_Header);
sectionHeader.setClickable(false);
return sectionHeader;
}
//Normal View... do what you would do normally
return customView;
}
希望对您有所帮助!让我知道..它对我有用
这是我的列表视图
我想在 2016-02-02
之上添加二月 header,在 2016-01-31
中添加一月。是否可以?
在android中叫做ExpandableListView
你可以试试这个教程:
http://www.androidhive.info/2013/07/android-expandable-list-view-tutorial/
它还有一个示例可供下载。
是的,您可以通过 return在适配器 class 的 getView() 方法中创建不同的视图来实现。在您传递给适配器的主列表中,您可以添加一个分隔项,一个字符串,或者您持有所有这些数据,我假设一个自定义 class,您知道它是为了显示月份标题.您可以快速检查您的 getView() 方法和 return 显示月份的不同视图..
在您的 getView() 方法中,您可以这样做...
@Override
public View getView(final int position, View convertView, ViewGroup parent){
LayoutInflater mInflator = LayoutInflater.from(getContext());
View customView = mInflator.inflate(R.layout.times_layout, parent, false);
Time temp = getItem(position);
//Check to see if the time is supposed to be a header
//This is where you check to see if it meant to be a section header
if(temp.getDate.equals("HEADER")){
//Header, return section view instead of normal view
View sectionHeader = mInflator.inflate(R.layout.layout_list_divider, parent, false);
TextView txt_Section = (TextView) sectionHeader.findViewById(R.id.txt_Header);
sectionHeader.setClickable(false);
return sectionHeader;
}
//Normal View... do what you would do normally
return customView;
}
希望对您有所帮助!让我知道..它对我有用