SHARE
TWEET

contoh get alarm status

a guest May 22nd, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.iqbal.homesecurity;
  2.  
  3.  
  4. import android.os.Bundle;
  5. import android.support.v4.app.Fragment;
  6. import android.util.Log;
  7. import android.view.LayoutInflater;
  8. import android.view.View;
  9. import android.view.ViewGroup;
  10. import android.widget.TextView;
  11.  
  12. import com.google.firebase.database.DataSnapshot;
  13. import com.google.firebase.database.DatabaseError;
  14. import com.google.firebase.database.DatabaseReference;
  15. import com.google.firebase.database.FirebaseDatabase;
  16. import com.google.firebase.database.ValueEventListener;
  17.  
  18.  
  19. /**
  20.  * A simple {@link Fragment} subclass.
  21.  */
  22. public class DashboardFragment extends Fragment {
  23.  
  24.     FirebaseDatabase database = FirebaseDatabase.getInstance();
  25.     DatabaseReference myRef = database.getReference();
  26.     private TextView textAlarmStatus;
  27.  
  28.     public DashboardFragment() {
  29.         // Required empty public constructor
  30.     }
  31.  
  32.  
  33.     @Override
  34.     public View onCreateView(LayoutInflater inflater, ViewGroup container,
  35.                              Bundle savedInstanceState) {
  36.         // Inflate the layout for this fragment
  37.         View view = inflater.inflate(R.layout.fragment_dashboard, container, false);
  38.  
  39.         // Read from the database
  40.         myRef.child("alarm_status").addValueEventListener(new ValueEventListener() {
  41.             @Override
  42.             public void onDataChange(DataSnapshot dataSnapshot) {
  43.                 // This method is called once with the initial value and again
  44.                 // whenever data at this location is updated.
  45.                 String value = dataSnapshot.getValue(String.class);
  46.  
  47.                 //contoh yg aku ditampilin di text view
  48.                 textAlarmStatus = getView().findViewById(R.id.txt_alarm_status);
  49.                 textAlarmStatus.setText(value);
  50.             }
  51.  
  52.             @Override
  53.             public void onCancelled(DatabaseError error) {
  54.                 // Failed to read value
  55.                 Log.w("ERROR", "Failed to read value.", error.toException());
  56.             }
  57.         });
  58.  
  59.         return view;
  60.     }
  61.  
  62. }
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
 
Top