Program Konversi Mata Uang Di Android Dengan Eclipse


Wahhh ketemu lagi nihh…
Malam gini ane gadak kegiatan, Bosen juga duduk aja di kost nungguin yang ga pasti dengerin temen sebelah kost ane lg Nonton Comic Story yg Cuma bisa ketawa terbahak-bahak liat tingkah si Babe yg salah satu pemeran nya di Comic Story..
Ane ikut sibuk juga di depan laptop  ngetik2 perintah coding yg struktur coding nya buat kepala pening kalo program ga bisa running..
Hehehe….
Langsung aja sob disini ane mau buat program Konversi Mata Uang Di Android Dengan Eclipse
Langsung saja sobat design project nya seperti ini;

 
Nah langsung ketikan perintah coding ini di .XML nya:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:text="Masukan Nilai" />

    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/textView1"
        android:ems="10"
        android:inputType="numberDecimal" />

    <RadioButton
        android:id="@+id/radioButton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/editText1"
        android:text="Dollar ke Rupiah" />

    <RadioButton
        android:id="@+id/radioButton2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/radioButton1"
        android:text="Rupiah ke Dollar" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/radioButton2"
        android:text="Proses" />

</RelativeLayout>



Nah setelah itu modifikasi coding ini di .JAVA nya;

package com.example.konversimatauang;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Toast;


public class MainActivity extends Activity {
/**Called when the activity is first created.*/
       private EditText etAngka;
       private RadioButton rbcf;
       private Button btnProses;
      
       @Override
       protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_main);
              etAngka = (EditText) findViewById
                           (R.id.editText1);
                            rbcf = (RadioButton) findViewById
                           (R.id.radioButton1);
                            rbcf.setChecked(true);
                            btnProses = (Button) findViewById
                           (R.id.button1);
                            
                             btnProses.setOnClickListener(new
                           View.OnClickListener ()
                            {
                                  public void onClick(View v) {
                                         kalkulasi();
                                  }
                               });
                       }
       public void kalkulasi (){
              double dollar = 10000;
              double angka = 0;
             
              try{
                     angka = Double.parseDouble(
                                  etAngka.getText ().toString());
              }catch (Exception e){
                     Toast.makeText(this, "Masukan Angka",
                                  Toast.LENGTH_LONG).show();
                    
                     }
              String hasil;
                if(rbcf.isChecked ()) {
                       hasil = angka + " dollar = " +
                       (angka * 10) + " rupiah";
                       } else {
                       hasil = angka + " rupiah = " +
                       (angka + dollar) + " dollar";
             }
                AlertDialog.Builder ab = new
                             AlertDialog.Builder(this);
                               ab.setTitle("Hasil");
                               ab.setMessage(hasil);
                               ab.setPositiveButton("Oke",
                               new DialogInterface.OnClickListener () {
                               public void onClick(DialogInterface
                             dialog ,
                               int which) {
                               dialog.dismiss ();
                               }
                               });
                               AlertDialog dialog = ab.create ();
                               dialog.show();
                               }
}
Nah coba di running program nya apakah hasil seperti ini:


 SELAMAT MENCOBA.....




Previous
Next Post »