我知道有这样的问题,但没有解决我的..
我正在尝试将 'RecyclerView' 设为 'OnItemClickListener' ,但是当我运行该应用程序时,它停止了。
你能告诉我错误在哪里吗?
这是代码:(请注意错误在于使项目可点击)
public class TeacherActivity extends AppCompatActivity {
private FirebaseAuth mAuth=FirebaseAuth.getInstance();
private FirebaseUser currentUser= mAuth.getCurrentUser();;
private FirebaseFirestore db = FirebaseFirestore.getInstance();
private String UserId =currentUser.getUid();
private static String city;
private TeacherAdapter teacherAdapter;
public static final String EXTRA_PATH = "com.example.exercise.EXTRA_PATH";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_teacher);
setUpRecyclerView();
teacherAdapter.setOnItemClickListener(new TeacherAdapter.OnItemClickListener() {
@Override
public void onItemClick(DocumentSnapshot documentSnapshot, int position) {
String path = documentSnapshot.getReference().getPath();
Intent intent = new Intent(TeacherActivity.this, SecondActivity.class);
intent.putExtra(EXTRA_PATH, path);
startActivity(intent);
}
});
}// end of onCreate
private void setUpRecyclerView(){
Query query = db.collection("Teachers");
FirestoreRecyclerOptions < Teacher > options = new
FirestoreRecyclerOptions.Builder<Teacher>()
.setQuery(query, Teacher.class)
.build();
teacherAdapter = new TeacherAdapter(options);
RecyclerView recyclerView = findViewById(R.id.recycler_view);
recyclerView.setHasFixedSize(true); //for performane reasons
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(teacherAdapter);
teacherAdapter.startListening();
}
@Override
protected void onStart() {
super.onStart();
}
@Override
protected void onStop() {
super.onStop();
teacherAdapter.stopListening();
}
}// end of class
慕莱坞森
相关分类