Guest User

Untitled

a guest
May 16th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. import android.support.v7.app.AppCompatActivity;
  2. import android.os.Bundle;
  3. import android.view.View;
  4. import android.widget.Button;
  5. import android.widget.EditText;
  6.  
  7. import com.google.firebase.database.DatabaseReference;
  8. import com.google.firebase.database.FirebaseDatabase;
  9.  
  10. public class MainActivity extends AppCompatActivity{
  11.  
  12. @Override
  13. protected void onCreate(Bundle savedInstanceState) {
  14. super.onCreate(savedInstanceState);
  15. setContentView(R.layout.activity_main);
  16.  
  17. final EditText edtPesan = (EditText)findViewById(R.id.edt_pesan);
  18. Button btnSend = (Button)findViewById(R.id.btn_pesan);
  19.  
  20. btnSend.setOnClickListener(new View.OnClickListener() {
  21. @Override
  22. public void onClick(View v) {
  23. String data = edtPesan.getText().toString();
  24. sendData(data);
  25. Toast.makeText(MainActivity.this, "terkirim", Toast.LENGTH_SHORT).show();
  26. }
  27. });
  28. }
  29.  
  30. private void sendData(String pesan) {
  31. FirebaseDatabase database = FirebaseDatabase.getInstance();
  32. DatabaseReference myRef = database.getReference("pesan");
  33.  
  34. myRef.setValue(pesan);
  35. }
  36. }
Add Comment
Please, Sign In to add comment