You are on page 1of 2

package com.example.

ongkirradio;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivityOngkir extends Activity {


RadioButton pil1;
RadioButton pil2;
RadioButton pil3;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_activity_ongkir);

final EditText berat = (EditText) findViewById(R.id.editText1);

RadioGroup pilihangroup = (RadioGroup)findViewById(R.id.radioGroup1);


pil1 = (RadioButton)findViewById(R.id.radio0);
pil2 = (RadioButton)findViewById(R.id.radio1);
pil3 = (RadioButton)findViewById(R.id.radio2);
pilihangroup.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
@Override
public void onCheckedChanged(RadioGroup arg0, int arg1) {
//TODO Auto-generate method stub
int valberat,valongkir=0,valhasil;
valberat=Integer.parseInt(berat.getText().toString());

if (pil1.isChecked())
{
valongkir = 20000;
valhasil=valberat*valongkir;
Toast.makeText(getBaseContext(), "Total Biaya "+valhasil+"
Rupiah.", Toast.LENGTH_LONG).show();
}
else if (pil2.isChecked())
{
valongkir = 30000;
valhasil=valberat*valongkir;
Toast.makeText(getBaseContext(), "Total Biaya "+valhasil+"
Rupiah.", Toast.LENGTH_LONG).show();
}
else
{
valongkir = 20000;
valhasil=valberat*valongkir;
Toast.makeText(getBaseContext(), "Total Biaya "+valhasil+"
Rupiah.", Toast.LENGTH_LONG).show();
}
}
});
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is
present.
getMenuInflater().inflate(R.menu.main_activity_ongkir, menu);
return true;
}