** Ich habe vier Radiobuttons zum Addieren und Subtrahieren des Betrags in der Brieftasche verwendet. Immer wenn ich die App öffne, stürzt es ab. Wann immer ich die App öffne, stürzt es ab. Ich weiß nicht, was Fehler ist. Bitte, jemand hilft mir. Ich bin neu bei Android. In dieser App habe ich vier Radiobuttons verwendet, um den Betrag hinzuzufügen und den Betrag zu subtrahieren. **wie Edittext innerhalb der Radiogruppe in Android verwenden?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/form"
tools:context="com.sivaneshsg.wallet.MainActivity">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Amount"
android:textSize="25sp"
android:textStyle="italic"
android:textColor="@android:color/black"
android:paddingTop="5dp"
android:paddingBottom="10dp"
android:paddingLeft="10dp"/>
<EditText
android:id="@+id/inputamount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Amount in Rs."
android:paddingTop="5dp"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:inputType="number"
android:ems="10"
/>
<RadioGroup
android:id="@+id/rgroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Income"
android:textStyle="italic"
android:textSize="20sp"
android:textColor="@android:color/black"
android:paddingBottom="10dp"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="@+id/cash1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cash"
android:textSize="15dp"
android:paddingRight="10dp"
android:textColor="@android:color/black"
/>
<RadioButton
android:id="@+id/card1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Card"
android:textColor="@android:color/black"
/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Expense"
android:textSize="20dp"
android:textStyle="italic"
android:textColor="@android:color/black"
android:paddingBottom="10dp"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="@+id/cash2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cash"
android:textColor="@android:color/black"
android:textSize="15sp"
android:paddingRight="10dp"
/>
<RadioButton
android:id="@+id/card2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Card"
android:textSize="15sp"
android:textColor="@android:color/black"
/>
</LinearLayout>
</RadioGroup>
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="OK"
/>
<TextView
android:id="@+id/amountcard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/black"
android:text="Amount in Card : RS. 0"
android:textSize="25sp"
android:padding="10dp"/>
<TextView
android:id="@+id/amountcash"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Amount in Cash : Rs. 0"
android:textSize="25sp"
android:textColor="@android:color/black"
android:padding="10dp"/>
<TextView
android:id="@+id/amountwallet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Total Amount in Wallet : RS. 0"
android:textSize="23sp"
android:textColor="@android:color/black"
android:textStyle="bold"
android:padding="10dp"/>
</LinearLayout>
package com.sivaneshsg.wallet;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;
import static android.icu.lang.UCharacter.GraphemeClusterBreak.T;
public class MainActivity extends AppCompatActivity {
int cashamount = 0;
int cardamount = 0;
int totalamount;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
EditText et = (EditText) findViewById(R.id.inputamount);
final int amount = Integer.parseInt(et.getText().toString());
RadioGroup rg = (RadioGroup) findViewById(R.id.rgroup);
rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
if (checkedId == R.id.card1) {
cardamount = cardamount + amount;
} else if (checkedId == R.id.cash1) {
cashamount = cashamount + amount;
} else if (checkedId == R.id.cash2) {
cashamount = cashamount - amount;
} else if (checkedId == R.id.card2) {
cardamount = cardamount - amount;
}
}
});
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TextView cash = (TextView) findViewById(R.id.amountcash);
TextView card = (TextView) findViewById(R.id.amountcard);
TextView wallet = (TextView) findViewById(R.id.amountwallet);
cash.setText("Amount in Cash : RS. " + cashamount);
card.setText("Amount in Card : RS. " + cardamount);
totalamount = cashamount + cashamount;
wallet.setText("Total Amount in Wallet : RS. " + totalamount);
}
});
}
}
**Whenever i open the app it crashes i don't what is error please someone help me. i am new to android. In this app i have used four radio buttons for add the amount and subtracting the amount. **
hier war Sie bitte XML-Datei –
** i hinzugefügt haben im Programm zeigen ** –