Advertisement
hendroprwk08

Untitled

Aug 23rd, 2020
1,169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.30 KB | None | 0 0
  1. ...
  2.  
  3. public class DetailActivity extends AppCompatActivity {
  4.     TextView tvNama, tvNPM, tvAlamat, tvProdi;
  5.     RadioGroup rgDomisili;
  6.     RadioButton rbDK, rbLK;
  7.     CheckBox cbxTeknologi, cbxKuliner;
  8.  
  9.     @Override
  10.     protected void onCreate(Bundle savedInstanceState) {
  11.         super.onCreate(savedInstanceState);
  12.         setContentView(R.layout.activity_detail);
  13.  
  14.         //definisi widget
  15.         tvNama = (TextView) findViewById(R.id.tv_nama);
  16.         tvNPM = (TextView) findViewById(R.id.tv_npm);
  17.         tvAlamat = (TextView) findViewById(R.id.tv_alamat);
  18.         tvProdi = (TextView) findViewById(R.id.tv_prodi);
  19.         cbxTeknologi = (CheckBox) findViewById(R.id.cb_teknologi);
  20.         cbxKuliner = (CheckBox) findViewById(R.id.cb_kuliner);
  21.         rgDomisili = (RadioGroup) findViewById(R.id.rg_domisili);
  22.         rbDK = (RadioButton) findViewById(R.id.rb_DK);
  23.         rbLK = (RadioButton) findViewById(R.id.rb_LK);
  24.  
  25.         //tangkap extra yang dikirim dari main activity
  26.         Intent i = getIntent();
  27.         tvNama.setText(i.getStringExtra("x_nama"));
  28.         tvNPM.setText(i.getStringExtra("x_npm"));
  29.         tvAlamat.setText(i.getStringExtra("x_alamat"));
  30.         tvProdi.setText(i.getStringExtra("x_prodi"));
  31.         cbxTeknologi.setChecked(i.getBooleanExtra("x_teknologi", false));
  32.         cbxKuliner.setChecked(i.getBooleanExtra("x_kuliner", false));
  33.  
  34.         String kelas = i.getStringExtra("x_domisili");
  35.         if (kelas.equals("Luar Kota")){
  36.             rbDK.setChecked(true);
  37.         }else{
  38.             rbLK.setChecked(true);
  39.         }
  40.  
  41.         /*
  42.         menampilkan tombol back ada 2 tahap
  43.         1. pada manifest harap ditentukan dahulu parent-nya
  44.         android:parentActivityName=".MainActivity"
  45.         2. agar memiliki fungsi yang sama dengan back button kode perlu di override
  46.         onOptionsItemSelected(MenuItem item)
  47.         */
  48.  
  49.         getSupportActionBar().setTitle("Detail Activity");
  50.         getSupportActionBar().setDisplayHomeAsUpEnabled(true);
  51.     }
  52.  
  53.     @Override
  54.     public boolean onOptionsItemSelected(MenuItem item) {
  55.         switch (item.getItemId()){
  56.             case android.R.id.home:
  57.                 finish();
  58.                 return true;
  59.             default:
  60.                 return super.onOptionsItemSelected(item);
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement