I have a custom listview which fetch data from firebasedatabase ,question is how im i able to sort my arraylist ex. "1 alexander" , "500 Airene" , "3 Airene","200 Aiexa"
Expected output : 500 Airene 200 Aiexa 3 Airene 1 Alexander
Im fetching and sorting it this way
FirebaseDatabase database = FirebaseDatabase.getInstance();
database.getReference()
.child("Users").child("Displayname")
.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot snapshot : dataSnapshot.getChildren()){
System.out.println(snapshot.getKey());
Map<String, Object> map =(Map<String, Object>) snapshot.getValue();
for (Map.Entry<String, Object> entry : map.entrySet()){
System.out.println(entry.getKey());
System.out.println(entry.getValue().toString());
Cred = (String) entry.getValue();
int numberOfUsers = (int) dataSnapshot.getChildrenCount();
UsersNumber.setText("Total Users : "+String.valueOf(numberOfUsers));
professions = new String[numberOfUsers];
Prof.add(Cred);
professions = new String[Prof.size()];
Prof.toArray(professions);
friend = snapshot.getKey();
names = new String[numberOfUsers];
Usersname.add(Cred+" "+friend);
names = new String[Usersname.size()];
Usersname.toArray(names);
names = new String[Usersname.size()];
Usersname.toArray(names);
customListView=(ListView)findViewById(R.id.custom_list_view);
userInfos=new ArrayList<>();
Arrays.sort(names, Collections.reverseOrder());
//Arrays.sort(names, String.CASE_INSENSITIVE_ORDER);
// Arrays.sort(professions, String.CASE_INSENSITIVE_ORDER);
customListAdapter=new CustomListAdapter(userInfos,MainActivityCustonlistViewnew.this);
customListView.setAdapter(customListAdapter);
getDatas();
// Toast.makeText(MainActivityCustonlistViewnew.this,String.valueOf(numberOfUsers) , Toast.LENGTH_SHORT).show();
customListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
// Toast.makeText(MainActivityCustonlistViewnew.this, "Name : " + names[i] + "\n Profession : " + professions[i], Toast.LENGTH_SHORT).show();
}
});
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
But when using this code my output is :
500 Airene
3 Airene
200 Aiexa
1 Alexander
Arrays.sort(names, Collections.reverseOrder());
is not working for me may be, because " number and alphabet" are combine as string"??
Usersname.add(Cred+" "+friend);