아래 첨부 된 사진에서 볼 수 있듯이 다른 장의 주제 개념을 제공하는 상위 recyclerView에 하위 recyclerView가 중첩되어 있습니다.
내 도전은 주어진 섹션 또는 장 (중첩 된 하위 RecyclerView)에서 선택한 단일 하위 항목 (주제)을 강조 표시합니다.
사진에서 볼 수 있듯이 다른 섹션 (챕터)에서 이전에 선택한 항목 (또는 주제)은 다른 섹션의 주제가 선택 될 때 선택 해제되지 않습니다. 누군가 중첩 된 recyclerView에서 선택한 항목을 강조 표시하는 가장 좋은 방법에 대한 힌트를 줄 수 있습니까?
다음은 Child RecyclerView에 대한 내 코드입니다.
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
Topic topic = topicList.get(position);
holder.clearSelection();
if (currentItemPosition == position) {
holder.position.setTextColor(holder.itemView.getResources().getColor(R.color.red));
holder.title.setTextColor(holder.itemView.getResources().getColor(R.color.red));
holder.description.setTextColor(holder.itemView.getResources().getColor(R.color.blue));
} else {
holder.position.setTextColor(holder.itemView.getResources().getColor(R.color.black));
holder.title.setTextColor(holder.itemView.getResources().getColor(R.color.black));
holder.description.setTextColor(holder.itemView.getResources().getColor(R.color.black));
}
holder.position.setText(String.valueOf(topic.getPosition()));
holder.title.setText(topic.getTitle());
holder.description.setText(topic.getDescription());
holder.duration.setText(topic.getDuration());
if (downloadedTopics.contains(topic.getTitle())) {
holder.downloadIcon.setImageResource(R.drawable.downloaded_icon);
} else {
holder.downloadIcon.setImageResource(R.drawable.undownloaded_icon);
}
}
여기에 상위 (또는 기본 RecyclerView)의 OnBindViewHolder가 있습니다.
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
ArrayList<View> topicViewList = new ArrayList<>();
RootTopic topicGroup = rootTopicsGroupList.get(position);
ArrayList<Topic>topicList = topicGroup.getTopicGroup();
String titleConstruct = "Chapter " + (position + 1) + "- " + topicGroup.getRootTopicName();
holder.SectionTitle.setText(titleConstruct);
setUpTopicGroupRec(topicList,downloadedTopicList,holder.groupedTopicsRV,holder.itemView.getContext());
}
다음은 setUpTopicGroupRec 메서드가 호출되었습니다.
private void setUpTopicGroupRec(ArrayList<Topic> topicList, ArrayList<String>downloads, RecyclerView recyclerView, Context context, ArrayList<RootTopic> rootTopicsGroupList){
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context,RecyclerView.VERTICAL,false);
topicAdapter = new TopicAdapter(topicList, downloads);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(linearLayoutManager);
recyclerView.setAdapter(topicAdapter);
topicAdapter.setOnItemClickListener(new TopicAdapter.OnItemClickListener() {
@Override
public void onTopicClick(int position, Topic topic) {
currentTopic = topic;
onTopicClickLD.postValue(currentTopic);
int currentTopicPos = topic.getPosition();
}
@Override
public void onDownloadIconClick(int position, Topic topic) {
currentTopic = topic;
onDownloadIconClickLD.postValue(currentTopic);
}
});
}
자식 리사이클 러 뷰 어댑터에서 특정 항목에 대한 onClick 이벤트를 수신하고 해당 위치를 확인하고 마지막으로 해당 위치의 항목에 변경 사항을 적용하는 코드를 추가합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다