gpt4 book ai didi

android - 具有可扩展 View 的 RecyclerView

转载 作者:行者123 更新时间:2023-11-30 00:33:36 25 4
gpt4 key购买 nike

我已经找到this包含如何做的答案的帖子。但是有些东西不起作用,我不明白为什么。

@Override
public void onBindViewHolder(final ShipViewer.anAdapter.NumberViewHolder holder, final int position) {

final int[] mExpandedPosition = {-1};
final boolean isExpanded = position== mExpandedPosition[0];
holder.details.setVisibility(isExpanded?View.VISIBLE:View.GONE);
holder.itemView.setActivated(isExpanded);
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mExpandedPosition[0] = isExpanded ? -1:position;
TransitionManager.beginDelayedTransition(recyclerView);
notifyDataSetChanged();
}
});
holder.bind(position);
}

首先,我无法解决细节问题。详细信息是我的 Viewholder 中的 ConstraintLayout:

<android.support.constraint.ConstraintLayout
android:id="@+id/details"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="0dp"
android:visibility="gone"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/bigtextname">

<TextView
android:id="@+id/textView10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</android.support.constraint.ConstraintLayout>

我的第二个问题是我无法解析 recyclerView。我已经尝试插入我的适配器,但这也不起作用。

最后,这么多东西在这里 final 可以吗?这似乎不对,但如果我不这样做,它会告诉我它们必须是最终的才能从内部类访问。

我的回收 View :

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ShipRec"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black">

</android.support.v7.widget.RecyclerView>

RecyclerView 的初始化:

View b = inflater.inflate(R.layout.shipviewerrecview, container, false);

if(!shipsCursor.moveToPosition(0)) {return b;}

shipropView = (RecyclerView) b.findViewById(R.id.ShipRec);
LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
shipropView.setLayoutManager(layoutManager);
shipropView.setHasFixedSize(true);
shippropAdapter = new ShipViewer.anAdapter(numberofField, Names, Type, Size, MaxSize, Amount);


ShipsDbHelper.close();
return b;

最佳答案

可能 expandable-recycler-view来自 bignerdranch 的库将对您有用。

关于android - 具有可扩展 View 的 RecyclerView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43802621/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com