1

我在为我的项目实施可扩展的 RecyclerView 时遇到问题。我不知道为什么,但是我的应用程序在单击时没有响应,cardView如果您查看我的代码并写下我可以解决的问题,如果您在其中发现一些错误,我将非常感激。所以首先...

public NoteHolder(View itemView) {
           super(itemView);
           textViewTitle = itemView.findViewById(R.id.text_view_title);
           textViewDescription = itemView.findViewById(R.id.text_view_description);
           textViewPriority = itemView.findViewById(R.id.text_view_priority);
           itemView.setOnClickListener(new View.OnClickListener() {
               @Override
               public void onClick(View v) {
                   int position = getAdapterPosition();
                   if (position != NO_POSITION && listener != null) {
                       listener.onItemClick(getSnapshots().getSnapshot(position), position);
                   }
               }

           });
       }
   }

在我NoteHolder的设置listeneronItemClick就可以了。那么让我们看看onItemClickHomeFragment 中的方法

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);
                 }
            }
        });

如果(位置!= NO_POSSITION){...}

if被执行了,我试着把它放进去Log.d,它显示了预期的消息。

4

0 回答 0