SHARE
TWEET

Untitled

a guest Jun 27th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class Collection extends AppCompatActivity {
  2.  
  3.     TextView ttl, tgat, tsch;
  4.     Button btnshw, btngt;
  5.     Spinner sping;
  6.     DatabaseReference d2ref;
  7.  
  8.     @Override
  9.     protected void onCreate(Bundle savedInstanceState) {
  10.         super.onCreate(savedInstanceState);
  11.         setContentView(R.layout.activity_collection);
  12.  
  13.         tgat = (TextView) findViewById(R.id.texigat);
  14.         tsch = (TextView) findViewById(R.id.texisch);
  15.         //tcls = (TextView) findViewById(R.id.texiclass);
  16.         ttl = (TextView) findViewById(R.id.texirs);
  17.         btnshw = (Button) findViewById(R.id.bshow);
  18.         btngt = (Button) findViewById(R.id.bgat);
  19.         sping = (Spinner) findViewById(R.id.spingat);
  20.  
  21.         btnshw.setOnClickListener(new View.OnClickListener() {
  22.             @Override
  23.             public void onClick(View v) {
  24.                 d2ref = FirebaseDatabase.getInstance().getReference().child("2018-19").child("Gat No 14")
  25.                         .child("School no 109").child("Standard 2nd");
  26.                 d2ref.addValueEventListener(new ValueEventListener() {
  27.                     @Override
  28.                     public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
  29.                         String rs = dataSnapshot.child("Rupees").getValue().toString();
  30.                         ttl.setText(rs);
  31.                     }
  32.  
  33.                     @Override
  34.                     public void onCancelled(@NonNull DatabaseError databaseError) {
  35.  
  36.                     }
  37.                 });
  38.             }
  39.         });
  40.  
  41.         btngt.setOnClickListener(new View.OnClickListener() {
  42.             @Override
  43.             public void onClick(View v) {
  44.         d2ref = FirebaseDatabase.getInstance().getReference().child("2018-19");
  45.         ValueEventListener eventListener = new ValueEventListener() {
  46.             @Override
  47.             public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
  48.                 final List<String> gatno = new ArrayList<String>();
  49.  
  50.                 for (DataSnapshot dsnap : dataSnapshot.child("Gat No 14").getChildren()) {
  51.                     String gat = dsnap.getKey();
  52.                     gatno.add(gat);
  53.                 }
  54.                 ArrayAdapter<String> adapter = new ArrayAdapter<String>(Collection.this, android.R.layout.simple_spinner_item);
  55.                 adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  56.                 sping.setAdapter(adapter);
  57.  
  58.                 /*I wasn't able to get the value in 1st spinner so I didn't
  59.                  wrote program for second spinner*/
  60.             }
  61.  
  62.             @Override
  63.             public void onCancelled(@NonNull DatabaseError databaseError) {
  64.  
  65.             }
  66.         };
  67.         d2ref.addListenerForSingleValueEvent(eventListener);
  68.             }
  69.         });
  70.     }
  71. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top