public class ShowCustomer extends AppCompatActivity {
FirebaseDatabase database;
DatabaseReference reference;
AddCustomer customer;
private EditText fname;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show_customer);
database = FirebaseDatabase.getInstance();
reference = database.getReference("Customers");
customer = new AddCustomer();
reference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot ds: dataSnapshot.getChildren() ) {
customer = ds.getValue(AddCustomer.class);
fname = (EditText) findViewById(R.id.fnameTxt);
fname.setKeyListener(null);
fname.setText(customer.getFname().toString());
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
}
Question: The customer name is getting displayed on the listview by retrieving them through firebase database. If i click on the items on the listview the details of the customers needs to be shown on another activity. Given bellow is the code segment of the listview onItemClickListner.
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(CustomerListView.this, ShowCustomer.class);
startActivity(intent);
}
});
The fname of the last customer is getting displayed if any item on the listview is tapped. Help me solve this problem. Thanks in advance.
The database structure is given here enter image description here