Created
November 3, 2015 02:56
-
-
Save ar-android/c97f8e162cf8f5079f36 to your computer and use it in GitHub Desktop.
simple firebase
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.ocit.wasap.activity; | |
| import android.os.Bundle; | |
| import android.support.v7.app.AppCompatActivity; | |
| import android.view.View; | |
| import android.widget.Button; | |
| import android.widget.TextView; | |
| import com.firebase.client.DataSnapshot; | |
| import com.firebase.client.Firebase; | |
| import com.firebase.client.FirebaseError; | |
| import com.firebase.client.ValueEventListener; | |
| import com.ocit.wasap.R; | |
| /** | |
| * Created by ar-android on 03/11/2015. | |
| */ | |
| public class BelajarFirebase extends AppCompatActivity{ | |
| private Button btn1, btn2; | |
| private TextView tv; | |
| private Firebase mRef; | |
| @Override | |
| protected void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| setContentView(R.layout.belajar_firebase); | |
| Firebase.setAndroidContext(this); | |
| } | |
| @Override | |
| protected void onStart() { | |
| super.onStart(); | |
| btn1 = (Button)findViewById(R.id.btn1); | |
| btn2 = (Button)findViewById(R.id.btn2); | |
| tv = (TextView)findViewById(R.id.tvAhmadRosid); | |
| mRef = new Firebase("https://belajarfierebase.firebaseio.com/ahmadrosid"); | |
| mRef.addValueEventListener(new ValueEventListener() { | |
| @Override | |
| public void onDataChange(DataSnapshot dataSnapshot) { | |
| String newAhmadrRosid = (String)dataSnapshot.getValue(); | |
| tv.setText(newAhmadrRosid); | |
| } | |
| @Override | |
| public void onCancelled(FirebaseError firebaseError) { | |
| } | |
| }); | |
| btn1.setOnClickListener(new View.OnClickListener() { | |
| @Override | |
| public void onClick(View v) { | |
| mRef.setValue("Ahmad"); | |
| } | |
| }); | |
| btn2.setOnClickListener(new View.OnClickListener() { | |
| @Override | |
| public void onClick(View v) { | |
| mRef.setValue("Rosid"); | |
| } | |
| }); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment