I am building an android app in which when the user create its account as a technician his name id display in a listview
in which other users which don't have firebase
outh.the problem is that I am unable to show data of technicians in the listview
.
This is my firebase
database
This is my code that return 0 items or blank listview
. I tried several things, but unable to display the information of technicians. Anyone please help me with this I am new in firebase
.
public class Technician extends Activity {
ListView listView;
ArrayList<String> tecnames = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_technician);
ImageButton Back_Btn = (ImageButton) findViewById(R.id.back);
Back_Btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(Technician.this, Technician_main.class);
startActivity(i);
finish();
}
});
listView = (ListView) findViewById(R.id.list_item);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Intent intent = new Intent(Technician.this, Book_Now.class);
startActivity(intent);
finish();
}
});
Technician.CostumAdapter costumAdapter = new Technician.CostumAdapter();
listView.setAdapter(costumAdapter);
GetItems();
}
private class CostumAdapter extends BaseAdapter {
@Override
public int getCount() {
return tecnames.size();
}
@Override
public Object getItem(int i) {
return null;
}
@Override
public long getItemId(int i) {
return 0;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
view = getLayoutInflater().inflate(R.layout.cuctom_listview, null);
TextView txt_one = (TextView) view.findViewById(R.id.skill_txt);
txt_one.setText(tecnames.get(i));
return view;
}
}
private void GetItems() {
DatabaseReference database = FirebaseDatabase.getInstance().getReference();
DatabaseReference ref = database.child("user");
final Query itemsQuery = ref.orderByChild("name");
itemsQuery.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.exists()) {
for (DataSnapshot singleSnapshot : dataSnapshot.getChildren()) {
Pojo item = singleSnapshot.getValue(Pojo.class);
tecnames.add(String.valueOf(item));
Log.e(TAG,"value of name"+itemsQuery);
}
}else {
Toast.makeText(getApplicationContext(),"error",Toast.LENGTH_LONG).show();
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
Log.e(TAG, "Returning " + tecnames.size() + " items");
}
}