Answer the question
In order to leave comments, you need to log in
How to make alphabetical list on left in RecyclerView?
I want to implement such a thing (group name/image on the left)
But I can't figure out how.
All that comes to mind is to put one list into another, but this option is confusing.
Prompt the literature, or an example what.
Answer the question
In order to leave comments, you need to log in
After reading the RecyclerView documentation for a hundred rows, I came across such a thing RecyclerView.ItemDecoration With it, you can change the list item according to a certain condition. I searched for examples on this topic and came across this . Changed the drawVertical method like this:
public void drawVertical(Canvas c, RecyclerView parent) {
final int left = this.dpToPx(72);
final int right = parent.getWidth() - this.dpToPx(16);
String firstLetter = "";
String previousFirstLetter = "";
TextView studentName;
TextView nextStudentName;
String nextFirstLetter = "";
TextView groupMarkerText;
final int childCount = parent.getChildCount();
for (int i = 0; i < childCount; i++) {
final View child = parent.getChildAt(i);
final View nextChild = parent.getChildAt(i + 1);
studentName = (TextView) child.findViewById(R.id.studentName);
groupMarkerText = (TextView) child.findViewById(R.id.groupMarkerText);
if (nextChild != null) {
nextStudentName = (TextView) nextChild.findViewById(R.id.studentName);
nextFirstLetter = (String) nextStudentName.getText().subSequence(0,1);
}
firstLetter = (String) studentName.getText().subSequence(0, 1);
if (!firstLetter.equals(previousFirstLetter)) {
groupMarkerText.setText(firstLetter);
groupMarkerText.setVisibility(View.VISIBLE);
}
if (!nextFirstLetter.equals(firstLetter)) {
final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
.getLayoutParams();
final int top = child.getBottom() + params.bottomMargin;
final int bottom = top + mDivider.getIntrinsicHeight();
mDivider.setBounds(left, top, right, bottom);
mDivider.draw(c);
}
previousFirstLetter = firstLetter;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question