Advertisement
gungdeaditya

DetailActivity

Aug 26th, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.55 KB | None | 0 0
  1. import android.content.Intent;
  2. import android.support.v7.app.AppCompatActivity;
  3. import android.os.Bundle;
  4. import android.view.View;
  5. import android.widget.Button;
  6. import android.widget.ImageView;
  7. import android.widget.TextView;
  8.  
  9. public class DetailActivity extends AppCompatActivity {
  10.  
  11.     private TextView txCost, txTitle, txLocation, txRating;
  12.     private ImageView image;
  13.     private Button btnShare;
  14.  
  15.     @Override
  16.     protected void onCreate(Bundle savedInstanceState) {
  17.         super.onCreate(savedInstanceState);
  18.         setContentView(R.layout.activity_detail);
  19.  
  20.         txCost = (TextView)findViewById(R.id.cost);
  21.         txTitle = (TextView)findViewById(R.id.title);
  22.         txLocation = (TextView)findViewById(R.id.location);
  23.         txRating = (TextView)findViewById(R.id.rating);
  24.         image = (ImageView) findViewById(R.id.image);
  25.         btnShare = (Button)findViewById(R.id.btn_share);
  26.  
  27.         if(getString(R.string.judul_hotel_inna).equals(getIntent().getStringExtra(MainActivity.nama_hotel1))){
  28.             image.setImageResource(R.drawable.ic_hotel1);
  29.             txTitle.setText(getString(R.string.judul_hotel_inna));
  30.             txCost.setText(getString(R.string.harga_hotel_inna));
  31.             txLocation.setText(getString(R.string.alamat_hotel_inna));
  32.             txRating.setText(getString(R.string.rating_hotel_inna));
  33.         }
  34.         else if(getString(R.string.judul_hotel_jaffara).equals(getIntent().getStringExtra(MainActivity.nama_hotel2))){
  35.             image.setImageResource(R.drawable.ic_hotel2);
  36.             txTitle.setText(getString(R.string.judul_hotel_jaffara));
  37.             txCost.setText(getString(R.string.harga_hotel_jaffara));
  38.             txLocation.setText(getString(R.string.alamat_hotel_jaffara));
  39.             txRating.setText(getString(R.string.rating_hotel_jaffara));
  40.         }
  41.  
  42.         btnShare.setOnClickListener(new View.OnClickListener() {
  43.             @Override
  44.             public void onClick(View view) {
  45.                 Intent i = new Intent();
  46.                 i.setAction(Intent.ACTION_SEND);
  47.                 i.putExtra(Intent.EXTRA_TEXT, txTitle.getText().toString()
  48.                         + "\n"
  49.                         + "Lokasi : " + txLocation.getText().toString()
  50.                         + "\n"
  51.                         + "Rating : " + txRating.getText().toString()
  52.                         + "\n"
  53.                         + "Harga : " + txCost.getText().toString()
  54.                 );
  55.                 i.setType("text/plain");
  56.                 startActivity(i);
  57.             }
  58.         });
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement