按时间范围查询Firebase [android]

时间:2016-01-25 14:47:14

标签: android time firebase

我需要寻找与当前时间相匹配的主题。例如,当前时间是1:30。因此,如果我将使用Firebase运行查询,则应返回主题Math。

这是我的JSON,其中“2012123458”是faculty_id。

schedule:{
     "2012123458" : {
  "Saturday" : {
    "-K8j0EkwmWjj3vMqB2d3" : {
      "classroom" : "Lab 3",
      "subject" : "Science",
      "time_end" : "2:00",
      "time_start" : "0:00"
    },
    "asdasdasd" : {
      "classroom" : "Lab 6",
      "subject" : "PE",
      "time_end" : "18:00",
      "time_start" : "17:00"
    },
    "qweqweqweqwe" : {
      "classroom" : "Lab 5",
      "subject" : "PE",
      "time_end" : "11:00",
      "time_start" : "9:00"
    }
  }
}
}

我试过这个但是返回一个NullPointerException

       gridView.setAdapter(listFaculty);
    gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            FacultyList faculty = (FacultyList) parent.getItemAtPosition(position);
            String faculty_id = faculty.getID();


            //Display schedule in a Dialog box
            final Dialog dialog = new Dialog(Faculty.this);
            dialog.setContentView(R.layout.dialog_sched);


           Firebase ref = new Firebase("https://infotrack.firebaseio.com/schedule/"+faculty_id+"/Saturday");
           ref.addListenerForSingleValueEvent(new ValueEventListener() {
               @Override
               public void onDataChange(DataSnapshot dataSnapshot) {
                   for(DataSnapshot postSnapshot: dataSnapshot.getChildren()){


                       schedule sched = postSnapshot.getValue(schedule.class);
                       TextView subject = (TextView) dialog.findViewById(R.id.txtSubject);
                       TextView time = (TextView) dialog.findViewById(R.id.txtTime);
                       TextView classroom = (TextView) dialog.findViewById(R.id.txtClassroom);

                       if(sched != null) {


                           if (checkTime(sched.getTime_start(), sched.getTime_end())){
                               Log.e("test", "x");

                                   Log.e("test", "" + dataSnapshot.getChildrenCount());

                                   Log.e("test", postSnapshot.getValue().toString());
                                   Log.e("test", "0");

                                   subject.setText(sched.getSubject());
                                   Log.e("test", sched.getSubject());


                                   time.setText(sched.getTime_start() + " - " + sched.getTime_end());
                                   Log.e("test", "2");


                                   classroom.setText(sched.getClassroom());
                               }

                        }  
                       else { 
                           Log.e("test", "null");
                       }

                   }
               }

               @Override
               public void onCancelled(FirebaseError firebaseError) {
                   Log.d("sched", firebaseError.getMessage());
               }
           });
           dialog.show();



       }
   });

日程安排课程:

public class schedule {

  private String subject;
  private String time_end;
  private String time_start;

  public schedule(){ }

  public schedule(String subject, String time_end, String time_start){

    this.subject = subject;
    this.time_end = time_end;
    this.time_start = time_start;

  }

  public String getSubject(){
    return subject;
  }

  public String getTime_end(){
    return time_end;
  }

  public String getTime_start(){
    return time_start;
  }
}

更新: 现在的问题是它对网格视图中的某些项不起作用。点击它后,它会将我带回我的应用程序的主屏幕。短时间内出现一个空对话框,然后返回主屏幕。

0 个答案:

没有答案