Reputation: 11
I have an app with user login, there is basic data such as Name, email,Age etc. but i want to display only 2 data for each user in a list view. Im pretty much a beginner in using ListView so i dont know where to start. Especially when Im using Fragment:
My code here:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
tutorList = (ListView) getView().findViewById(R.id.tutorListView);
tutorArrayList = new ArrayList<String>();
tutorAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, tutorArrayList);
databaseReference = FirebaseDatabase.getInstance().getReference().getRoot();
databaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
databaseReference = FirebaseDatabase.getInstance().getReference().child("Users").child("Tutees").child(userID);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
I'm also get confused which one to put in onCreate() method or onCreateView() method since im using fragment.
here's my json Structure in firebase:
"Users" : {
"Tutors" : {
"daBTEVRQagX7XbwPbXE5X1l3tg62" : {
"Age" : "22",
"District" : "miami",
"Email" : "[email protected]",
"Name" : "Ainul",
"Qualification" : "hnd",
"profileImageUrl" : "https://firebasestorage.googleapis.com/v0/b/tutorpal-1.appspot.com/o/profileImageUrl%2FdaBTEVRQagX7XbwPbXE5X1l3tg62?alt=media&token=a81ccf26-091d-4001-aa23-04665ad27173"
},
"glk3Wi1lZZOQkt2UNsGit02DEym2" : {
"profileImageUrl" : "https://firebasestorage.googleapis.com/v0/b/tutorpal-1.appspot.com/o/profileImageUrl%2Fglk3Wi1lZZOQkt2UNsGit02DEym2?alt=media&token=61192989-93c8-4c55-bca0-9d2b3a6a78fe"
},
"yE6ALyKEjVOoNLZcHEvHmeYkqON2" : {
"FullName" : "hai im ainul ",
"UserName" : "ainul",
"profileImageUrl" : "https://firebasestorage.googleapis.com/v0/b/tutorpal-1.appspot.com/o/profileImageUrl%2FyE6ALyKEjVOoNLZcHEvHmeYkqON2?alt=media&token=aa63a6f2-0154-4c27-b7ba-d8de89ee64bc"
}
}
}
basically i want to access Users-Tutors-Users-all their information
I also want the listview to be set as onclicklistener so whenever user click a user, it will bring to another activity which is the profileActivity of the user. I already have the profileactivity view set but dont know how to do this from a listView to ProfileActivity
Upvotes: 0
Views: 797
Reputation: 191701
First, I suggest you read about FirebaseUI library and try to get examples working
Basically, you're missing a ListView.setAdapter
If you want to have click events, adapter.setOnItemClickListener
I'm also get confused which one to put in onCreate() method or onCreateView() method since im using fragment.
Ideally, only onCreateView returns the inflated View. onViewCreated is where you use findViewById for a Fragment. You cannot call getView from onCreate
Upvotes: 1