My recycler view has a parent and a child. My parent is only displaying one item with then all the topics in that one item. I can post my code below I'm not sure what it is I need to do to correct this as this is my first time using expandable views. I've posted the whole class below. Not sure what was needed for you to see.
public class TopicFragment extends Fragment {
private View mRootView;
private CategoryResponse mData;
private CategoryFeedDataFactory mDataFactory;
private List<String> mCategories;
//Expandable Recycler View
private List<TopicItem> mTopics;
private TopicResponse mTopic;
private TopicFeedDataFactory mTopicDataFactory;
private CategoryItem mCategoryItem;
//RecyclerView
private RecyclerView mRecyclerView;
private LinearLayoutManager mLayoutManager;
private TopicExpandableAdapter mExpandableAdapter;
public TopicFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
mRootView = inflater.inflate(R.layout.fragment_topic, container, false);
initUI();
return mRootView;
}
private void initUI() {
mRecyclerView = (RecyclerView) mRootView.findViewById(R.id.categoryView);
mLayoutManager = new LinearLayoutManager(getActivity().getApplication().getApplicationContext());
loadData();
}
private void loadData() {
mDataFactory = new CategoryFeedDataFactory(getActivity().getApplicationContext());
mTopicDataFactory = new TopicFeedDataFactory(getActivity().getApplicationContext());
mDataFactory.getCategoryFeed(new CategoryFeedDataFactory.CategoryFeedDataFactoryCallback() {
@Override
public void onCategoryDataReceived(CategoryResponse response) {
mData = response;
}
@Override
public void onCategoryDataFailed(Exception exception) {
}
});
mTopicDataFactory.getAllTopics(new TopicFeedDataFactory.TopicFeedDataFactoryCallback() {
@Override
public void onTopicDataReceived(TopicResponse response) {
mTopic = response;
populateUIWithData();
}
@Override
public void onTopicDataFailed(Exception exception) {
}
});
}
private void populateUIWithData() {
mCategories = new ArrayList<>();
mTopics = new ArrayList<>();
for (int i = 0; i <= mData.getItems().size(); i++) {
if (mData != null) {
if (mData.getItem(i) != null) {
if (mData.getItem(i).getCategoryItem() != null &&
mData.getItem(i).getCategoryItem().getName() != null) {
mCategories.add(mData.getItem(i).getCategoryItem().getName());
}
}
}
for (int j = 0; j <= mTopic.getItems().size(); j++) {
if (mTopic != null)
if (mTopic.getItem(j) != null)
if (mTopic.getItem(j).getTopicItem() != null)
if (mTopic.getItem(j).getTopicItem().getCategoryID() != null) {
if (mData.getItem(i) != null && mData.getItem(i).getCategoryItem() != null)
if (mData.getItem(i).getCategoryItem().getId() != null)
if (mTopic.getItem(j).getTopicItem().getCategoryID().equals
(mData.getItem(i).getCategoryItem().getId())) {
mTopics.add(mTopic.getItem(j).getTopicItem());
mCategoryItem =
new CategoryItem(mData.getItem(i).getCategoryItem().getName(),
mTopics);
}
}
}
}
final List<CategoryItem> categoryItems = Collections.singletonList(mCategoryItem);
mExpandableAdapter = new TopicExpandableAdapter(getActivity(), categoryItems);
mExpandableAdapter.setExpandCollapseListener(new ExpandableRecyclerAdapter.ExpandCollapseListener() {
@Override
public void onListItemExpanded(int position) {
CategoryItem expandedCategoryItem = categoryItems.get(position);
String toastMsg = getResources().getString(R.string.expanded, expandedCategoryItem);
Toast.makeText(getActivity().getApplicationContext(),
toastMsg,
Toast.LENGTH_SHORT)
.show();
}
@Override
public void onListItemCollapsed(int position) {
CategoryItem collapsedCategoryItem = categoryItems.get(position);
String toastMsg = getResources().getString(R.string.collapsed, collapsedCategoryItem.getName());
Toast.makeText(getActivity().getApplicationContext(),
toastMsg,
Toast.LENGTH_SHORT)
.show();
}
});
mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
mRecyclerView.setAdapter(mExpandableAdapter);
}
}
Am I just missing something really simple? Because this feels really complicated lol
Thanks in advance!