firebase - 有没有办法通过使用 FirestoreRecyclerAdapter 使 recyclerview 可扩展?
问题描述
是否可以像 onBindViewHolder 一样扩展每个持有者?如何获取位置并使用isExpanded?
编辑
所以这就是我到目前为止在我的 recyclerView 中使用 FirestoreRecyclerAdapter 所做的。我还没有弄清楚如何构建我的 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>
解决方案
推荐阅读
- c# - 是否可以从 Windows 任务调度程序使用/不使用命令行参数启动/触发桌面桥接应用程序(Win32)?
- c# - Android问题以编程方式更改应用程序语言
- python - 当数据量很大时,如何正确绘制数据框的两列?
- azure-active-directory - 在 Azure Active Directory B2C 自定义策略中自定义用户界面
- sql-server - 修复 SQL Server 标识并恢复正确的编号顺序
- reactjs - 无法将状态数据作为道具发送到另一个组件
- ios - 单击 UISearchBar 时如何用 tableview 替换屏幕上的内容
- python - Python 3 - 格式化打印命令
- react-native - 必须在 React-native 中使用“新”错误调用类构造函数
- ruby-on-rails - 从独立页面在 ruby on rails 中添加关联值