Advertisement
Guest User

MainActivity JAVA

a guest
Nov 22nd, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.28 KB | None | 0 0
  1. package com.android.ale.llaundry;
  2.  
  3. import android.content.Intent;
  4. import android.support.v7.app.AppCompatActivity;
  5. import android.os.Bundle;
  6. import android.view.Menu;
  7. import android.view.MenuItem;
  8. import android.view.View;
  9. import android.widget.Button;
  10. import android.widget.EditText;
  11. import android.widget.RadioGroup;
  12. import android.widget.TextView;
  13. import android.widget.Toast;
  14.  
  15. public class MainActivity extends AppCompatActivity {
  16.  
  17. EditText nama, alamat, telepon;
  18. Button order;
  19. RadioGroup paket;
  20. @Override
  21.  
  22. public boolean onCreateOptionsMenu (Menu menu){
  23. getMenuInflater().inflate(R.menu.menu, menu);
  24. return true;
  25. }
  26. @Override
  27. public boolean onOptionsItemSelected(MenuItem item){
  28. switch (item.getItemId()){
  29. case R.id.action_contact:
  30. Intent intent_show = new Intent(MainActivity.this, ContactUs.class);
  31. intent_show.putExtra(Intent.EXTRA_TEXT,"Contact Us");
  32. startActivity(intent_show);
  33.  
  34. //ke halaman tampilan semula
  35. return true;
  36.  
  37. case R.id.action_home:
  38. Intent intent_delete = new Intent(MainActivity.this, MainActivity.class);
  39. intent_delete.putExtra(Intent.EXTRA_TEXT, "Data dari halaman main");
  40. startActivity(intent_delete);
  41.  
  42. return true;
  43.  
  44. }
  45. return super.onOptionsItemSelected(item);
  46.  
  47. }
  48.  
  49.  
  50. @Override
  51. protected void onCreate(Bundle savedInstanceState) {
  52. super.onCreate(savedInstanceState);
  53. setContentView(R.layout.activity_main);
  54.  
  55.  
  56.  
  57. nama = (EditText) findViewById(R.id.edit_nama);
  58. alamat = (EditText) findViewById(R.id.edit_alamat);
  59. telepon = (EditText) findViewById(R.id.edit_telepon);
  60. order = (Button) findViewById(R.id.button_order);
  61. paket = (RadioGroup) findViewById(R.id.group_paket);
  62.  
  63. order.setOnClickListener(new View.OnClickListener() {
  64. @Override
  65. public void onClick(View v) {
  66.  
  67.  
  68.  
  69. if (nama.getText().toString().length() == 0) {
  70. nama.setError("Nama tidak boleh kosong!");
  71. } else if (nama.getText().toString().length() > 20) {
  72. nama.setError("Nama Tidak Boleh lebih dari 20 Karakter");
  73. } else if (alamat.getText().toString().length() == 0) {
  74. alamat.setError("Alamat tidak boleh kosong!");
  75. } else if (alamat.getText().toString().length() > 20) {
  76. alamat.setError("Alamat Tidak Boleh lebih dari 20 Karakter");
  77. } else if (telepon.getText().toString().length() == 0) {
  78. telepon.setError("Telepon tidak boleh kosong!");
  79. } else {
  80. Toast.makeText(getApplicationContext(), "Order Berhasil! Silahkan tunggu kurir kami mengambil cucian",
  81. Toast.LENGTH_SHORT).show();
  82.  
  83. String order = "Nama : " + nama + "\n";
  84. order = order + "Alamat : " + alamat + "\n";
  85. order = order + "Paket : " + paket + "\n";
  86. order = order + "Telepon : " + telepon + "\n";
  87.  
  88. }
  89.  
  90.  
  91.  
  92.  
  93. }
  94.  
  95. });
  96.  
  97.  
  98.  
  99. }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement