我正在尝试将用户集合中的学生提取到“回收者视图”中,但是它说没有附加的adpater。.提取了两件事(1)学生姓名(2)列表视图中的卷号
public class availablestudent_fragment extends Fragment {
private static final String TAG ="FireLog" ;
private RecyclerView nmainlist;
private FirebaseFirestore mfirestore;
private List<Users> usersList;
private UserListAdapter userListAdapter;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v=inflater.inflate(R.layout.fragment_availablestudents,null);
nmainlist=(RecyclerView)v.findViewById(R.id.main_list);
nmainlist.setHasFixedSize(true);
nmainlist.setLayoutManager(new LinearLayoutManager(getContext()));
nmainlist.setAdapter(userListAdapter);
mfirestore=FirebaseFirestore.getInstance();
usersList=new ArrayList<>();
userListAdapter=new UserListAdapter(usersList);
mfirestore.collection("users").addSnapshotListener(new EventListener<QuerySnapshot>() {
@Override
public void onEvent(@javax.annotation.Nullable QuerySnapshot queryDocumentSnapshots, @javax.annotation.Nullable FirebaseFirestoreException e) {
if (e != null) {
Log.d(TAG, "Error" + e.getMessage());
}
for (DocumentChange doc : queryDocumentSnapshots.getDocumentChanges()) {
if (doc.getType() == DocumentChange.Type.ADDED) {
Users users = doc.getDocument().toObject(Users.class);
usersList.add(users);
userListAdapter.notifyDataSetChanged();
}
}
}
});
return v;
}
}
适配器类
public class UserListAdapter extends RecyclerView.Adapter<UserListAdapter.ViewHolder> {
public List<Users> usersList;
public UserListAdapter(List<Users>usersList){
this.usersList=usersList;
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int i) {
View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item,parent,false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
holder.studentName.setText(usersList.get(position).getStudentName());
holder.rollNumber.setText(usersList.get(position).getRollNumber());
}
@Override
public int getItemCount() {
return usersList.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
View mview;
public TextView studentName;
public TextView rollNumber;
public ViewHolder(@NonNull View itemView) {
super(itemView);
mview=itemView;
studentName=(TextView)mview.findViewById(R.id.name);
rollNumber=(TextView)mview.findViewById(R.id.rollnumber);
}
}
}
模型类
public class Users {
String studentName, rollNumber;
public Users(){}
public Users(String studentName, String rollNumber) {
this.studentName = studentName;
this.rollNumber = rollNumber;
}
public String getStudentName() {
return studentName;
}
public void setStudentName(String studentName) {
this.studentName = studentName;
}
public String getRollNumber() {
return rollNumber;
}
public void setRollNumber(String rollNumber) {
this.rollNumber = rollNumber;
}
}
现在的问题是,提取卷号与提取学生姓名的方法相同,这是否对我造成了问题?
logcat
03-31 19:13:40.978 10522-10596/com.kiit.projectmanager D/FA: Logging event (FE): user_engagement(_e), Bundle[{firebase_event_origin(_o)=auto, engagement_time_msec(_et)=6812, firebase_screen_class(_sc)=login_activity, firebase_screen_id(_si)=-4085041765426975583}]
03-31 19:13:46.971 10522-10522/com.kiit.projectmanager E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
03-31 19:13:46.972 10522-10522/com.kiit.projectmanager E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
03-31 19:13:47.781 10522-10522/com.kiit.projectmanager E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
03-31 19:13:47.781 10522-10522/com.kiit.projectmanager E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
03-31 19:13:52.009 10522-10522/com.kiit.projectmanager W/IInputConnectionWrapper: getExtractedText on inactive InputConnection
03-31 19:13:52.013 10522-10522/com.kiit.projectmanager W/IInputConnectionWrapper: getTextBeforeCursor on inactive InputConnection
03-31 19:13:52.098 10522-10522/com.kiit.projectmanager W/IInputConnectionWrapper: setComposingRegion on inactive InputConnection
03-31 19:13:55.485 10522-10522/com.kiit.projectmanager W/BiChannelGoogleApi: [FirebaseAuth: ] getGoogleApiForMethod() returned Gms: com.google.firebase.auth.api.internal.zzal@c973a77
03-31 19:13:58.673 10522-10568/com.kiit.projectmanager D/FirebaseAuth: Notifying id token listeners about user ( yBhPtTpYDdQgviffTlUvhLwAOPn1 ).
03-31 19:13:58.690 10522-10522/com.kiit.projectmanager D/FirebaseApp: Notifying auth state listeners.
03-31 19:13:58.690 10522-10522/com.kiit.projectmanager D/FirebaseApp: Notified 0 auth state listeners.
03-31 19:13:58.707 10522-10522/com.kiit.projectmanager I/Timeline: Timeline: Activity_launch_request time:133537931
03-31 19:13:58.786 10522-10596/com.kiit.projectmanager D/FA: Logging event (FE): user_engagement(_e), Bundle[{firebase_event_origin(_o)=auto, engagement_time_msec(_et)=17881, firebase_screen_class(_sc)=student_login, firebase_screen_id(_si)=-4085041765426975582}]
03-31 19:13:58.935 10522-11447/com.kiit.projectmanager W/DynamiteModule: Local module descriptor class for providerinstaller not found.
03-31 19:13:58.940 10522-11447/com.kiit.projectmanager I/DynamiteModule: Considering local module providerinstaller:0 and remote module providerinstaller:0
03-31 19:13:58.940 10522-11447/com.kiit.projectmanager W/ProviderInstaller: Failed to load providerinstaller module: No acceptable module found. Local version is 0 and remote version is 0.
03-31 19:13:58.941 10522-11447/com.kiit.projectmanager W/ResourceType: No package identifier when getting name for resource number 0x00000000
03-31 19:13:58.945 10522-10596/com.kiit.projectmanager D/FA: Logging event (FE): screen_view(_vs), Bundle[{firebase_event_origin(_o)=auto, firebase_previous_class(_pc)=student_login, firebase_previous_id(_pi)=-4085041765426975582, firebase_screen_class(_sc)=student_activity, firebase_screen_id(_si)=-4085041765426975581}]
03-31 19:13:59.006 10522-11447/com.kiit.projectmanager W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --non-interactive --runtime-arg -Xms64m --runtime-arg -Xmx512m -j2 --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.google.android.gms-2/base.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.google.android.gms-2@base.apk@classes.dex) because non-0 exit status
03-31 19:13:59.081 10522-10596/com.kiit.projectmanager D/FA: Connected to remote service
03-31 19:14:00.384 10522-11447/com.kiit.projectmanager I/art: Rejecting re-init on previously-failed class java.lang.Class<com.google.android.gms.org.conscrypt.Java7ExtendedSSLSession>
03-31 19:14:00.385 10522-11447/com.kiit.projectmanager I/art: Rejecting re-init on previously-failed class java.lang.Class<com.google.android.gms.org.conscrypt.Java7ExtendedSSLSession>
03-31 19:14:00.385 10522-11447/com.kiit.projectmanager I/art: Rejecting re-init on previously-failed class java.lang.Class<com.google.android.gms.org.conscrypt.Java8ExtendedSSLSession>
03-31 19:14:00.385 10522-11447/com.kiit.projectmanager I/art: Rejecting re-init on previously-failed class java.lang.Class<com.google.android.gms.org.conscrypt.Java8ExtendedSSLSession>
03-31 19:14:00.416 10522-11447/com.kiit.projectmanager I/ProviderInstaller: Installed default security provider GmsCore_OpenSSL
03-31 19:14:03.276 10522-10522/com.kiit.projectmanager W/PathParser: Points are too far apart 4.000000596046461
03-31 19:14:10.542 10522-10522/com.kiit.projectmanager W/PathParser: Points are too far apart 4.000000596046461
03-31 19:14:10.579 10522-10522/com.kiit.projectmanager E/RecyclerView: No adapter attached; skipping layout
答案 0 :(得分:0)
我看到您初始化了userListAdapter
.cs
之后,您将适配器设置为mainList
usersList=new ArrayList<>();
也许那是错误的,因为我在控制台日志中看到:
nmainlist.setAdapter(userListAdapter);