Ich bin neu hier in Firebase meine Frage ist, wie man die Daten von Firebase holt das folgende Bild zeigt die Details meiner Datenbank.Firebase-Datenbank Daten abrufen?
Ich möchte die Daten von user_time_table
in der Uid abrufen, da in jeder UID gibt es Savientage werden in jedem Tag angezeigt, es gibt Zeit und Steckplatz sind da ich möchte diese Schleppdaten in ListView abrufen und wie in der anzeigen Bild unten
, wie ich die Zeit von Firebase zu holen haben?
object class
public String uid;
public String username;
public String address;
public String day;
public String slot;
public long time;
public int starCount = 0;
public Map<String, Boolean> stars = new HashMap<>();
public drPost() {
// Default constructor required for calls to DataSnapshot.getValue(Post.class)
}
public drPost(String uid, String username, String address, String day, String slot, long time) {
this.uid = uid;
this.username = username;
this.address = address;
this.day = day;
this.slot = slot;
this.time = time;
}
// [START post_to_map]
@Exclude
public Map<String, Object> toMap() {
HashMap<String, Object> result = new HashMap<>();
result.put("uid", uid);
result.put("address", address);
result.put("day", day);
result.put("slot", slot);
result.put("time", time);
result.put("starCount", starCount);
result.put("stars", stars);
return result;
}
// [END post_to_map]
public long getTime() {
return time;
}
public String getSlot(){
return slot;
}
public String getDay(){
return day;
}
}
// [END post_class]
/// und Blick holen ///
enter code here
public class timetable extends Activity {
ListView listView, listView2;
List<drPost> drpostList = new ArrayList<>();
// DatabaseReference databasetimeandslot;
DatabaseReference databaseReference;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_timetable);
databaseReference = FirebaseDatabase.getInstance().getReference().child("user_time_table").child("userID");
// Get ListView object from xml
listView = (ListView) findViewById(R.id.list1);
listView2 = (ListView) findViewById(R.id.list1);
drpostList = new ArrayList<>();
// Defined Array values to show in ListView
String[] values = new String[]{
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
"Sunday"
};
// Define a new Adapter
// First parameter - Context
// Second parameter - Layout for the row
// Third parameter - ID of the TextView to which the data is written
// Forth - the Array of data
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
R.layout.timetable_items, R.id.type, values);
// Assign adapter to ListView
listView.setAdapter(adapter);
// ListView Item Click Listener
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// ListView Clicked item index
int itemPosition = position;
// ListView Clicked item value
String itemValue = (String) listView.getItemAtPosition(position);
Intent intent = new Intent(timetable.this, EditTimeTable.class);
intent.putExtra("key", itemValue);
startActivity(intent);
// Show Alert
Toast.makeText(getApplicationContext(), "" + itemValue, Toast.LENGTH_LONG).show();
}
});
}
@Override
protected void onStart() {
super.onStart();
databaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
//clearing the previous artist list
drpostList.clear();
//iterating through all the nodes
for (DataSnapshot postSnapshot : dataSnapshot.getChildren()) {
//getting artist
drPost drpost = postSnapshot.getValue(drPost.class);
//adding artist to the list
drpostList.add(drpost);
}
//creating adapter
timeandslot artistAdapter = new timeandslot(timetable.this, drpostList);
//attaching adapter to the listview
listView2.setAdapter(artistAdapter);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
}
enter code here
public class timeandslot extends ArrayAdapter<drPost> {
private Activity context;
List<drPost> drpost;
public timeandslot(Activity context, List<drPost> drpost) {
super(context, R.layout.timetable_items, drpost);
this.context = context;
this.drpost = drpost;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
View listViewItem = inflater.inflate(R.layout.timetable_items, null, true);
// TextView version_TIME = (TextView) listViewItem.findViewById(R.id.version_TIME);
TextView version_SLOT = (TextView) listViewItem.findViewById(R.id.version_SLOT);
TextView Day = (TextView) listViewItem.findViewById(R.id.type);
drPost drposts = drpost.get(position);
// version_TIME.setText((int) drposts.getTime());
version_SLOT.setText(drposts.getSlot());
Day.setText(drposts.getDay());
return listViewItem;
}
}
Sie sollten wahrscheinlich die [Erste Schritte] (https durchlaufen://firebase.google.com/docs/database/android/lists-of-data), um zu erfahren, wie Sie Daten aus Firebase abrufen können. – Jay