java - 如何获取突出显示的节点并在卡片视图中显示它们?
问题描述
我正在使用地理围栏应用程序,因为我有一个名为 Location history logs 的活动,我想在单独的卡片视图中从位置日志中检索日期(2019 年 3 月 20 日)的每个数据节点和(2019 年 3 月 21 日)从单独的卡片视图中的位置日志等到当前日期,我该怎么做?这是我的firebase数据库的链接:
这是我的模型类:
public class locationHistoryModel {
private String Address, Key;
private long Entered, Exited;
public locationHistoryModel() {
}
public locationHistoryModel(String address_child, String key, long entered) {
this.Address = address_child;
Key = key;
Entered = entered;
}
public String getAddress() {
return this.Address;
}
public void setAddress(String address) {
this.Address = address;
}
public String getKey() {
return Key;
}
public void setKey(String key) {
Key = key;
}
public long getEntered() {
return Entered;
}
public void setEntered(long entered) {
Entered = entered;
}
public long getExited() {
return Exited;
}
public void setExited(long exited) {
Exited = exited;
}
}
这是我的适配器类:
public class LocationhistoryAdapter extends RecyclerView.Adapter<LocationhistoryAdapter.MyViewHolder>{
private Context mctx;
private ArrayList<locationHistoryModel> locationHistories;
public LocationhistoryAdapter(Context context, ArrayList<locationHistoryModel> locationHistoryArrayList )
{
mctx = context;
locationHistories = locationHistoryArrayList;
}
@NonNull
@Override
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
return new LocationhistoryAdapter.MyViewHolder(LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.layout_location_historyadapter,viewGroup,false));
}
@Override
public void onBindViewHolder(@NonNull MyViewHolder myViewHolder, int i) {
myViewHolder.Addresstxt.setText(locationHistories.get(i).getAddress());
myViewHolder.EnterTimeTxt.setText(String.valueOf(locationHistories.get(i).getEntered()));
myViewHolder.location.setText(locationHistories.get(i).getKey());
}
@Override
public int getItemCount() {
return locationHistories.size();
}
public class MyViewHolder extends RecyclerView.ViewHolder
{
TextView Addresstxt,EnterTimeTxt,location;
public MyViewHolder(@NonNull View itemView) {
super(itemView);
Addresstxt = itemView.findViewById(R.id.Address_child);
EnterTimeTxt = itemView.findViewById(R.id.Entered_timestamp);
location = itemView.findViewById(R.id.Location_child);
}
}
}
这是我的 MainActivity 类:
public class MainActivity extends AppCompatActivity {
RecyclerView recyclerView;
ArrayList<locationHistoryModel> locationHistoryList;
DatabaseReference databaseReference;
DatabaseReference databaseReference1;
DatabaseReference databaseReference2;
DatabaseReference databaseReference3;
String date;
String location;
locationHistoryModel historyModel;
LocationhistoryAdapter locationAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
recyclerView = findViewById(R.id.childsRecycler);
locationHistoryList = new ArrayList<>();
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.scrollToPosition(0);
databaseReference = FirebaseDatabase.getInstance().getReference("Child");
databaseReference1 = databaseReference.child("+923452267601")
.child("03326325635")
.child("LocationLogs");
databaseReference1.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot dataSnapshot1 : dataSnapshot.getChildren()) {
date = dataSnapshot1.getKey();
System.out.println(date + "dateee keeeeeyyyyy");
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
databaseReference2 = databaseReference.child("+923452267601")
.child("03326325635")
.child("Locations");
databaseReference2.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot dataSnapshot1 : dataSnapshot.getChildren()) {
location = dataSnapshot1.getKey();
System.out.println(location + "Location Key");
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
System.out.println("03326325635");
databaseReference3 = databaseReference.child("+923452267601")
.child("03326325635")
.child("LocationLogs");
databaseReference3.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
historyModel = dataSnapshot.child(date).child(location).getValue(locationHistoryModel.class);
historyModel.setKey(location);
locationHistoryList.add(historyModel);
System.out.println(historyModel.getAddress() + "haha" + historyModel.getKey() + "" + historyModel.getEntered());
locationAdapter = new LocationhistoryAdapter(MainActivity.this, locationHistoryList);
recyclerView.setAdapter(locationAdapter);
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
}
解决方案
推荐阅读
- functional-programming - 如何在 Erlang 中比较两个映射的值。[我的解决方案没有返回任何值]
- python-3.x - 如何防止 geckodriver+selenium (python) 打开新的 firefox 实例
- nginx - 错误:horizontalpodautoscalers.autoscaling“nginx-1-hpa”已经存在
- python-3.x - 子类化 rv_continuous 时的溢出错误
- c# - 使用 WebClient UploadFile 线程被中止
- hibernate - Querydsl Projection.bean 找不到设置器
- debugging - VS2017调试错误:评估函数超时,需要中止...
- oracle - 联合投掷错误
- r - 来自维基百科的 R 图:数字被错误地解释为因素
- java - 错误:尝试在空对象引用上调用虚拟方法“android.content.Context.getResources()”