lawang code

lawang Code


Tanyakan kode disini

Gimana cara mengatasi unfortunately app has stopped ketika saya klik tombol btnHitung?

ditanyakan oleh usep muhammad 4 tahun yang lalu
package com.muhammadusep.zakatapp;

/**
 * Created by Muhammad Usep on 18/05/2015.
 */
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
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.RadioGroup;
import android.widget.Toast;

import static android.widget.Toast.makeText;
import static java.lang.Double.parseDouble;

public class Emas extends Activity {
    private EditText txtHarga, txtPunya, txtNishab, txtHasil;
    private RadioButton radio, radio2;
    private Button btnReset, btnBack, btnExit, btnHitung;
    private RadioGroup radioGroup1;
    final Context context = this;
    private View view;

    /**
     * Method yang dipanggil pada saat applikaasi dijalankan
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.emasdanperak);
        radioGroup1 = (RadioGroup) findViewById(R.id.radioGroup1);
        radio = (RadioButton) findViewById(R.id.radio);
        radio2 = (RadioButton) findViewById(R.id.radio2);
        txtHarga = (EditText) findViewById(R.id.txtHarga);
        txtPunya = (EditText) findViewById(R.id.txtPunya);
        txtHasil = (EditText) findViewById(R.id.txtHasil);
        btnHitung = (Button) findViewById(R.id.btnHitung);
        btnReset = (Button) findViewById(R.id.btnReset);
        btnBack = (Button) findViewById(R.id.btnBack);
        btnExit = (Button) findViewById(R.id.btnExit);

        btnExit.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);

                // set title
                alertDialogBuilder.setTitle("Keluar Aplikasi");

                // set dialog message
                alertDialogBuilder.setMessage("Apakah Anda Ingin Keluar dari Aplikasi?")
                        .setCancelable(false)
                        .setPositiveButton("Ya", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                // if this button is clicked, close
                                // current activity
                                Emas.this.finish();
                            }
                        })
                        .setNegativeButton("Tidak", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                // if this button is clicked, just close
                                // the dialog box and do nothing
                                dialog.cancel();
                            }
                        });

                // create alert dialog
                AlertDialog alertDialog = alertDialogBuilder.create();

                // show it
                alertDialog.show();
            }
        });
        btnHitung.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                hitungZakat();
            }
        });
        btnReset.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                radio.setSelected(false);
                radio2.setSelected(false);
                radioGroup1.clearCheck();
                txtHarga.setText("");
                txtPunya.setText("");
                txtNishab.setText("");
                txtHasil.setText("");
            }
        });
        btnBack.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    double ambilHarga() {
        double a = Double.parseDouble(txtHarga.getText().toString());
        double b = Double.parseDouble(txtPunya.getText().toString());
        double c = a * b;
        return (c);
    }

    private void pilihRadioButton() {
        if (radio.isSelected()) {
            double a = Double.parseDouble(txtNishab.getText().toString());
            double c = a * 85;
            if (ambilHarga() >= c) {
                Toast.makeText(Emas.this, "Anda sudah mencapai nishab!!! Anda wajib mengeluarkan zakat", Toast.LENGTH_LONG).show();
                double d = ambilHarga() * 25 / 1000;
                txtHasil.setText("Rp. " + String.valueOf(d) + ",00");

            } else {
                Toast.makeText(Emas.this, "Anda belum mencapai nishab!!! Anda tidak wajib mengeluarkan zakat", Toast.LENGTH_LONG).show();
            }
        }
        if (radio2.isSelected()) {
            double a = Double.parseDouble(txtHarga.getText().toString());
            double c = a * 595;
            if (ambilHarga() >= c) {
                Toast.makeText(Emas.this, "Anda sudah mencapai nishab!!! Anda wajib mengeluarkan zakat", Toast.LENGTH_LONG).show();
                double d = ambilHarga() * 25 / 1000;
                txtHasil.setText("Rp. " + String.valueOf(d) + ",00");

            } else {
                Toast.makeText(Emas.this, "Anda belum mencapai nishab!!! Anda tidak wajib mengeluarkan zakat", Toast.LENGTH_LONG).show();
            }
        }
    }

    public void hitungZakat () {
        txtNishab.setText("" + (ambilHarga()));
        pilihRadioButton();
}

}

Menampilkan 1-2 dari 2 hasil
imam menjawab 4 tahun yang lalu :

coba gini aj dech ane bingung juga banyak yg blum di tampilin soalnya gan dsna coba kayak code :

package com.example.zakat;

import android.app.Activity;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.TextView;
/***kayak gni */
public class hewan extends Activity{
    Button hitung;
    EditText jumlah;
     RadioButton onta,sapi,kambing;
    TextView hasilh;
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.hewan);
        jumlah=(EditText)findViewById(R.id.jumlah);
        onta=(RadioButton)findViewById(R.id.radio_onta);
          onta.setChecked(true);
        sapi=(RadioButton)findViewById(R.id.radio_sapi);
        kambing=(RadioButton)findViewById(R.id.radio_kambing);
        hitung=(Button)findViewById(R.id.btnhitung);
        hasilh=(TextView)findViewById(R.id.hasilh);

        hitung.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                int jum=Integer.parseInt(jumlah.getText().toString());


                if(onta.isChecked()){
                    if(jum>=5 && jum<=9 ){
                        hasilh.setText("1 Kambing umur 2th/1 domba umur 1th");

                    }else if(jum>=10 && jum<=14){
                        hasilh.setText("2 Kambing umur 2th/2 domba umur 1th");

                    }

                }

                if(sapi.isChecked()){

                    if(jum>=30 && jum<=39 ){
                        hasilh.setText("1 sapi umur genap 1th");

                    }else if(jum>=40 && jum<=59){
                        hasilh.setText("1 sapi umur genap 2th");

                    }
                }



                if(kambing.isChecked()){

                    if(jum>=40 && jum<=120 ){
                        hasilh.setText("1 kambing umur genap 1th");

                    }else if(jum>=121 && jum<=200){
                        hasilh.setText("2 kambing umur genap 2th");

                    }
                }else if(jum>=201 && jum<=399){
                    hasilh.setText("3 kambing umur genap 2th");

                }

                }


        });

    }

}




tsukiyamai menjawab 4 tahun yang lalu :

komment aja gan, isi dari fungsi tombol btnHitung.. hihihi..


Anda harus login terlebih dahulu untuk memberikan komentar

Recent Tag

X 6
X 48
X 14
X 10
X 1
X 5
X 4
X 18
X 10

Bantuan

Help

Feedback

Help