/** * This method creates a new cell and fill it with content. getView() calls this method when a * view needs to be created. * * @param index Entry's index relative to its section * @return */ public void generateCellContent( int sectionIndex, KrollDict data, TiListViewTemplate template, TiBaseListViewItem itemContent, int itemPosition, View item_layout) { // Here we create an item content and populate it with data // Get item proxy TiViewProxy itemProxy = template.getRootItem().getViewProxy(); // Create corresponding TiUIView for item proxy TiListItem item = new TiListItem( itemProxy, (TiCompositeLayout.LayoutParams) itemContent.getLayoutParams(), itemContent, item_layout); // Connect native view with TiUIView so we can get it from recycled view. itemContent.setTag(item); if (data != null && template != null) { generateChildContentViews(template.getRootItem(), null, itemContent, true); populateViews(data, itemContent, template, itemPosition, sectionIndex, item_layout); } }
@Override public View getView(int position, View convertView, ViewGroup parent) { // Get section info from index Pair<ListSectionProxy, Pair<Integer, Integer>> info = getSectionInfoByEntryIndex(position); ListSectionProxy section = info.first; int sectionItemIndex = info.second.second; int sectionIndex = info.second.first; // check marker if (sectionIndex > marker[0] || (sectionIndex == marker[0] && sectionItemIndex >= marker[1])) { proxy.fireEvent(TiC.EVENT_MARKER, null, false); resetMarker(); } View content = convertView; // Handles header/footer views and titles. if (section.isHeaderView(sectionItemIndex) || section.isFooterView(sectionItemIndex)) { return section.getHeaderOrFooterView(sectionItemIndex); } else if (section.isHeaderTitle(sectionItemIndex) || section.isFooterTitle(sectionItemIndex)) { // No content to reuse, so we create a new view if (content == null) { content = inflater.inflate(headerFooterId, null); } TextView title = (TextView) content.findViewById(titleId); title.setText(section.getHeaderOrFooterTitle(sectionItemIndex)); return content; } // Handling templates KrollDict data = section.getListItemData(sectionItemIndex); TiListViewTemplate template = section.getTemplateByIndex(sectionItemIndex); if (content != null) { TiBaseListViewItem itemContent = (TiBaseListViewItem) content.findViewById(listContentId); section.populateViews(data, itemContent, template, sectionItemIndex, sectionIndex, content); } else { content = inflater.inflate(listItemId, null); TiBaseListViewItem itemContent = (TiBaseListViewItem) content.findViewById(listContentId); LayoutParams params = new LayoutParams(); params.autoFillsWidth = true; itemContent.setLayoutParams(params); section.generateCellContent( sectionIndex, data, template, itemContent, sectionItemIndex, content); } return content; }