use of eu.davidea.samples.flexibleadapter.items.HeaderItem in project FlexibleAdapter by davideas.
the class DatabaseService method newHeader.
/*---------------*/
/* ITEM CREATION */
/*---------------*/
/*
* Creates a Header item.
*/
public static HeaderItem newHeader(int i) {
HeaderItem header = new HeaderItem("H" + i);
header.setTitle("Header " + i);
//header is hidden and un-selectable by default!
return header;
}
use of eu.davidea.samples.flexibleadapter.items.HeaderItem in project FlexibleAdapter by davideas.
the class DatabaseService method createHeadersSectionsDatabase.
/*
* List of Simple Items with Header attached. Only Simple Items will be added to the list.
*/
public void createHeadersSectionsDatabase(int size, int headers) {
databaseType = DatabaseType.HEADERS_SECTIONS;
HeaderItem header = null;
mItems.clear();
int lastHeaderId = 0;
for (int i = 0; i < size; i++) {
header = i % Math.round(size / headers) == 0 ? newHeader(++lastHeaderId) : header;
mItems.add(newSimpleItem(i + 1, header));
}
}
use of eu.davidea.samples.flexibleadapter.items.HeaderItem in project FlexibleAdapter by davideas.
the class MainActivity method extractTitleFrom.
private String extractTitleFrom(IFlexible flexibleItem) {
if (flexibleItem instanceof AbstractItem) {
AbstractItem exampleItem = (AbstractItem) flexibleItem;
String title = exampleItem.getTitle();
if (exampleItem instanceof ExpandableItem) {
ExpandableItem expandableItem = (ExpandableItem) flexibleItem;
if (expandableItem.getSubItems() != null) {
title += "(+" + expandableItem.getSubItems().size() + ")";
}
}
return title;
} else if (flexibleItem instanceof HeaderItem) {
HeaderItem headerItem = (HeaderItem) flexibleItem;
return headerItem.getTitle();
}
// We already covered all situations with instanceof
return "";
}
use of eu.davidea.samples.flexibleadapter.items.HeaderItem in project FlexibleAdapter by davideas.
the class MainActivity method onTitleModified.
/* ===============================================================
* DIALOG LISTENER IMPLEMENTATION (For the example of onItemClick)
* =============================================================== */
@Override
public void onTitleModified(int position, String newTitle) {
AbstractFlexibleItem abstractItem = mAdapter.getItem(position);
assert abstractItem != null;
if (abstractItem instanceof AbstractItem) {
AbstractItem exampleItem = (AbstractItem) abstractItem;
exampleItem.setTitle(newTitle);
} else if (abstractItem instanceof HeaderItem) {
HeaderItem headerItem = (HeaderItem) abstractItem;
headerItem.setTitle(newTitle);
}
mAdapter.updateItem(position, abstractItem, null);
}
use of eu.davidea.samples.flexibleadapter.items.HeaderItem in project FlexibleAdapter by davideas.
the class FragmentViewPager method createList.
private List<IFlexible> createList(int size, int headers) {
HeaderItem header = null;
List<IFlexible> items = new ArrayList<>();
int lastHeaderId = 0;
for (int i = 0; i < size; i++) {
header = i % Math.round(size / headers) == 0 ? DatabaseService.newHeader(++lastHeaderId) : header;
items.add(DatabaseService.newSimpleItem(i + 1, header));
}
return items;
}
Aggregations