gpt4 book ai didi

java - 我需要将所有工作概述保存在一个数组列表中,抱歉,如果有一个明显的答案,我对 java 和 android 很陌生

转载 作者:太空宇宙 更新时间:2023-11-04 11:08:06 25 4
gpt4 key购买 nike

数据库

this is a image of the database I am referring to

我尝试过使用 orderByChild 和嵌套 for 循环,但我不确定如何使用哪种方法或如何使用它。目的是在JOBOVERVIEW中显示各种字符串的卡片。各位 stackoverflowrians 有答案吗?我已经被困了一段时间,不知道从哪里开始。

干杯,请不要讨厌。

package com.example.sherwin.todo;

import java.util.ArrayList;

public class JobList extends Fragment {

public JobList() {
}
public static JobList newInstance() {
JobList fragment = new JobList();

return fragment;
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.fragment_job_list, container, false);
final RecyclerView recyclerView = (RecyclerView)rootView.findViewById(R.id.job_list_recycler_view);

LinearLayoutManager llm = new LinearLayoutManager(getContext());
recyclerView.setLayoutManager(llm);
final ArrayList<JobClass> joblistclass = new ArrayList<>();

final DatabaseReference myRef = FirebaseDatabase.getInstance().getReference("USERS/04950F4AE53F80/JOBS");



myRef.addValueEventListener(new ValueEventListener() {

@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot data:dataSnapshot.getChildren()
) {
if (data.getChildren().equals("JOBOVERVIEW")){
JobClass jblst = data.getValue(JobClass.class);
joblistclass.add(jblst);
}
}

final JobListRecyclerAdapter adapterb = new JobListRecyclerAdapter(joblistclass);
recyclerView.setAdapter(adapterb);

}



@Override
public void onCancelled(DatabaseError error) {
// Failed to read value
Log.w("TAG:", "Failed to read value.", error.toException());
}
});


return rootView;
}

}

最佳答案

要实现此目的,请使用以下代码:

DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
DatabaseReference jobsRef = rootRef
.child("USERS")
.child("04950F4AE53F80")
.child("JOBS");
ValueEventListener eventListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot ds : dataSnapshot.getChildren()) {
String jobDate = ds.child("JOBOVERVIEW").child("jobDate").getValue(String.class);
Log.d("TAG", jobDate);
}
}

@Override
public void onCancelled(DatabaseError databaseError) {}
};
jobsRef.addListenerForSingleValueEvent(eventListener);

输出将是:

29/09
2/2
//and so on

关于java - 我需要将所有工作概述保存在一个数组列表中,抱歉,如果有一个明显的答案,我对 java 和 android 很陌生,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46274070/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com