我正在尝试制作一个问题应用程序,让学生可以向老师提问。在问题片段中,我使用浮动操作按钮添加问题。它可以单击,然后转到添加页面的问题,但是当我将检索到的数据从Firebase的片段添加到Recycler-view时,就不再可以单击了,请有人可以帮我。
package com.example.dell.step;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import com.getbase.floatingactionbutton.FloatingActionButton;
import com.google.firebase.firestore.DocumentChange;
import com.google.firebase.firestore.EventListener;
import com.google.firebase.firestore.FirebaseFirestore;
import com.google.firebase.firestore.FirebaseFirestoreException;
import com.google.firebase.firestore.QuerySnapshot;
import java.util.ArrayList;
import java.util.List;
/**
* A simple {@link Fragment} subclass.
*/
public class QuestionsFragment extends Fragment {
private RecyclerView question_list_view;
private List<QuestionPost> question_list;
private FirebaseFirestore firebaseFirestore;
private QuestionRecyclerAdapter questionRecyclerAdapter;
public QuestionsFragment() {
// Required empty public constructor
}
FloatingActionButton fab;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
//Here we create floating action button
View view = inflater.inflate(R.layout.fragment_questions, container, false);
question_list_view = view.findViewById(R.id.question_list_view);
question_list = new ArrayList<>();
firebaseFirestore = FirebaseFirestore.getInstance();
questionRecyclerAdapter = new QuestionRecyclerAdapter(question_list);
question_list_view.setLayoutManager(new LinearLayoutManager(getActivity()));
question_list_view.setAdapter(questionRecyclerAdapter);
question_list_view.setHasFixedSize(true);
firebaseFirestore.collection("questions").addSnapshotListener(new EventListener<QuerySnapshot>() {
@Override
public void onEvent(QuerySnapshot documentSnapshots, FirebaseFirestoreException e) {
for (DocumentChange doc: documentSnapshots.getDocumentChanges()) {
if(doc.getType() == DocumentChange.Type.ADDED){
QuestionPost questionPost = doc.getDocument().toObject(QuestionPost.class);
question_list.add(questionPost);
questionRecyclerAdapter.notifyDataSetChanged();
}
}
}
});
fab = view.findViewById(R.id.Ask_question);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(getActivity(),"Working", Toast.LENGTH_LONG).show();
Intent fileIntent = new Intent(getActivity(), Add_question.class);
startActivity(fileIntent);
}
});
// Inflate the layout for this fragment
return view;
}
}
questionfragment.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.dell.step.QuestionsFragment">
<!-- TODO: Update blank fragment layout -->
<com.getbase.floatingactionbutton.FloatingActionsMenu
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
app:fab_addButtonColorNormal="@color/colorPrimaryDark"
app:fab_addButtonColorPressed="@color/colorPrimary"
app:fab_labelStyle="@style/floatingBtn_style">
<com.getbase.floatingactionbutton.FloatingActionButton
android:id="@+id/Ask_question"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:fab_colorNormal="@color/colorPrimaryDark"
app:fab_colorPressed="@color/colorPrimary"
app:fab_icon="@mipmap/ic_launcher_question"
app:fab_size="mini"
app:fab_title="Ask Question"
/>
</com.getbase.floatingactionbutton.FloatingActionsMenu>
<android.support.v7.widget.RecyclerView
android:id="@+id/question_list_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true" />
</RelativeLayout>