Java 带Firestore的可扩展回收视图。怎么做?
我在为我的项目实现可扩展的RecyclerView时遇到问题。我不知道为什么,但我的应用程序在点击Java 带Firestore的可扩展回收视图。怎么做?,java,android,firebase,android-recyclerview,expandablerecyclerview,Java,Android,Firebase,Android Recyclerview,Expandablerecyclerview,我在为我的项目实现可扩展的RecyclerView时遇到问题。我不知道为什么,但我的应用程序在点击cardwiew时没有响应。如果您查看我的代码并编写我可以修复的代码(如果您发现其中有错误),我将不胜感激。所以首先 在我的中,记事本设置为listener,上面有onItemClick。那么让我们看看HomeFragment中的onItemClick方法 public class HomeFragment extends Fragment {... FirestoreRecyclerOptio
cardwiew
时没有响应。如果您查看我的代码并编写我可以修复的代码(如果您发现其中有错误),我将不胜感激。所以首先
在我的中,记事本
设置为listener
,上面有onItemClick
。那么让我们看看HomeFragment中的onItemClick
方法
public class HomeFragment extends Fragment {...
FirestoreRecyclerOptions<Note> options = new FirestoreRecyclerOptions.Builder<Note>()
.setQuery(query, Note.class)
.build();
adapter = new NoteAdapter(options);
RecyclerView recyclerView = RootView.findViewById(R.id.recycler_view);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
recyclerView.setAdapter(adapter);
//DetailView
View CardView = inflater.inflate(R.layout.note_item, container, false);
final ConstraintLayout cardView = CardView.findViewById(R.id.relativeLayout);
adapter.setOnItemClickListener(new NoteAdapter.OnItemClickListener() {
@Override
public void onItemClick(final DocumentSnapshot documentSnapshot, int position) {
Note note = documentSnapshot.toObject(Note.class);
int pathInt = position;
constraintLayout = cardView.findViewById(R.id.expandableLayout);
String path =String.valueOf(pathInt);
if(possition != NO_POSSITION) {
Animation slideDown = AnimationUtils.loadAnimation(context, R.anim.slide_out_top);
constraintLayout.setVisibility(View.VISIBLE);
//adding sliding effect
constraintLayout.startAnimation(slideDown);
}
}
});
公共类HomeFragment扩展了片段{。。。
FirestoreRecyclerOptions选项=新建FirestoreRecyclerOptions.Builder()
.setQuery(查询,Note.class)
.build();
适配器=新的NoteAdapter(选项);
RecyclerView RecyclerView=RootView.findViewById(R.id.recycler\u视图);
recyclerView.setHasFixedSize(true);
setLayoutManager(新的LinearLayoutManager(getContext());
recyclerView.setAdapter(适配器);
//详细视图
视图卡视图=充气机。充气(R.layout.note_项目,容器,假);
最终约束Layout cardView=cardView.findViewById(R.id.relativeLayout);
setOnItemClickListener(新的NoteAdapter.OnItemClickListener(){
@凌驾
public void onItemClick(最终文档快照文档快照,内部位置){
Note=documentSnapshot.toObject(Note.class);
int pathInt=位置;
constraintLayout=cardView.findViewById(R.id.expandableLayout);
字符串路径=String.valueOf(pathInt);
如果(占有!=无占有){
Animation slideDown=AnimationUtils.loadAnimation(上下文,R.anim.slide\u out\u top);
constraintLayout.setVisibility(View.VISIBLE);
//添加滑动效果
constraintLayout.startAnimation(向下滑动);
}
}
});
if(position!=NO_position){…}
这个如果执行了
,我试着把它放入Log.d
,它显示了预期的消息
public class HomeFragment extends Fragment {...
FirestoreRecyclerOptions<Note> options = new FirestoreRecyclerOptions.Builder<Note>()
.setQuery(query, Note.class)
.build();
adapter = new NoteAdapter(options);
RecyclerView recyclerView = RootView.findViewById(R.id.recycler_view);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
recyclerView.setAdapter(adapter);
//DetailView
View CardView = inflater.inflate(R.layout.note_item, container, false);
final ConstraintLayout cardView = CardView.findViewById(R.id.relativeLayout);
adapter.setOnItemClickListener(new NoteAdapter.OnItemClickListener() {
@Override
public void onItemClick(final DocumentSnapshot documentSnapshot, int position) {
Note note = documentSnapshot.toObject(Note.class);
int pathInt = position;
constraintLayout = cardView.findViewById(R.id.expandableLayout);
String path =String.valueOf(pathInt);
if(possition != NO_POSSITION) {
Animation slideDown = AnimationUtils.loadAnimation(context, R.anim.slide_out_top);
constraintLayout.setVisibility(View.VISIBLE);
//adding sliding effect
constraintLayout.startAnimation(slideDown);
}
}
});