public class HomeScreen_Contacts extends Fragment {
TextView noUsersText;
ProgressDialog mProgressDialogue;
FirebaseAuth mAuth;
FirebaseUser currentUser;
String UID;
String name;
String rId;
ArrayAdapter<String> adapter;
ListView usersList;
ArrayList<String> al = new ArrayList<>();
ListView listView;
DatabaseReference rootRef;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View rootView = inflater.inflate(R.layout.fragment_contacts, container, false);
usersList = (ListView) rootView.findViewById(R.id.usersList);
noUsersText = (TextView) rootView.findViewById(R.id.noUsersText);
mAuth = FirebaseAuth.getInstance();
currentUser = mAuth.getCurrentUser();
UID = mAuth.getCurrentUser().getUid();
mProgressDialogue = new ProgressDialog(getActivity());
mProgressDialogue.setMessage("Loading...");
mProgressDialogue.show();
rootRef = FirebaseDatabase.getInstance().getReference();
listView = (ListView) rootView.findViewById(R.id.usersList);
readData(new MyCallback() {
@Override
public void onCallback(List<String> al) {
for (String name : al) {
Log.d("TAG", name);
}
}
});
usersList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(getActivity(), Chat.class);
intent.putExtra("Recievers_Id", rId);
intent.putExtra("Recievers_Name", name);
Log.d("RID", rId);
Log.d("RN", name);
startActivity(intent);
}
});
return rootView;
}
public void readData(final MyCallback myCallback) {
DatabaseReference usersRef = rootRef.child("Users");
ValueEventListener eventListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, android.R.id.text1, al);
for (DataSnapshot ds : dataSnapshot.getChildren()) {
name = ds.child("Name").getValue().toString();
rId = ds.child("Phone_Number").getValue().toString();
al.add(name);
}
listView.setAdapter(adapter);
mProgressDialogue.dismiss();
myCallback.onCallback(al);
}
@Override
public void onCancelled(DatabaseError databaseError) {
Toast.makeText(getActivity(), "Please Check Your Internet Connection", Toast.LENGTH_SHORT).show();
}
};
usersRef.addListenerForSingleValueEvent(eventListener);
}
public interface MyCallback {
void onCallback(List<String> al);
}
}
Whichever item i click on directs me to the same room. i want to change that. i want the user to go to a different room depending on which item he clicks in the listview. Is my logic correct? If yes where have i gone wrong
Followed the tutorial. Not sure on what should come under myCallback... left it blank... can u help me out pleas
Updated my code again... anything wrong?