-
Notifications
You must be signed in to change notification settings - Fork 0
/
ListDataActivity.java
81 lines (51 loc) · 2.21 KB
/
ListDataActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package com.example.adi18.blood;
import android.content.Intent;
import android.database.Cursor;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.Toast;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import java.util.ArrayList;
import java.util.List;
public class ListDataActivity extends AppCompatActivity {
DatabaseHelper mDatabaseHelper;
ArrayList<User> userList;
ListView mlistView;
User user;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_layout);
mDatabaseHelper = new DatabaseHelper(this);
mlistView = (ListView) findViewById(R.id.listView);
Cursor data = mDatabaseHelper.getData();
userList = new ArrayList<User>();
int rows = data.getCount();
if (rows == 0)
Toast.makeText(ListDataActivity.this, "Nothing in the database", Toast.LENGTH_LONG).show();
else {
while (data.moveToNext()) {
user = new User(data.getString(1), data.getString(2), data.getString(3), data.getString(4), data.getString(5), data.getString(6), data.getString(7), data.getString(8));
userList.add(user);
}
EightColumnsAdapter adapter = new EightColumnsAdapter(ListDataActivity.this, R.layout.list_adaptor, userList);
mlistView.setAdapter(adapter);
}
if (userList.size() > 0) {
final DatabaseReference ref = FirebaseDatabase.getInstance().getReference().child("foo");
ref.push().setValue(user);
}
}
}