是否可以像在onBindViewHolder中那样扩展每个持有人?如何获得位置并使用isExpanded?
编辑
所以这是我到目前为止使用FirestoreRecyclerAdapter在recyclerView中所做的事情。我还没有弄清楚如何构造我的xml并将其扩展到我的适配器上。我想先隐藏搜索栏,并在它扩展时显示它。
这是我的适配器
public class TaskAdapter extends FirestoreRecyclerAdapter <Activities, TaskAdapter.TaskHolder> {
private static final String TAG = "TaskAdapter";
TaskListener listener;
public TaskAdapter(@NonNull FirestoreRecyclerOptions<Activities> options, TaskListener listener) {
super(options);
this.listener = listener;
}
@Override
protected void onBindViewHolder(@NonNull TaskHolder holder, int position, @NonNull Activities activities) {
holder.tvTitle.setText(activities.getTitle());
}
@NonNull
@Override
public TaskHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
View view = layoutInflater.inflate(R.layout.layout_list_tasks, parent, false);
return new TaskAdapter.TaskHolder(view);
}
class TaskHolder extends RecyclerView.ViewHolder{
TextView tvTitle, tvPercent;
ConstraintLayout expandableLayout;
public TaskHolder(@NonNull View itemView) {
super(itemView);
tvTitle = itemView.findViewById(R.id.tvActivityTitle);
expandableLayout = itemView.findViewById(R.id.expandableLayout);
}
}
public interface TaskListener{
void onItemClick(DocumentSnapshot documentSnapshot, int position);
}
}
这是我的XML
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="8dp">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp">
<androidx.constraintlayout.widget.ConstraintLayout xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tvActivityTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:ellipsize="end"
android:maxLines="1"
android:padding="16dp"
android:text="Title"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/expandableLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:visibility="visible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tvActivityTitle">
<TextView
android:id="@+id/percent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="%"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.appcompat.widget.AppCompatSeekBar
android:id="@+id/seekBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
app:layout_constraintStart_toEndOf="@+id/percent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>