I have radio button group and spinner in my android activity.First, I choose a radio button, then I choose spinner item. I want to see selected spinner item in textView. However, when I change spinner item, textView does not update. It updates only when I change radio button. How can I update textView dynamically? I am trying to product my radio button and spinner and display on textView.
public class GenelBagis extends AppCompatActivity {
Spinner spinnerGenelBagis;
ArrayAdapter<String> dataAdapterForGenelBagis;
String[] aylar;
TextView mText;
int amount=1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_genel_bagis);
aylar = getResources().getStringArray(R.array.month);
spinnerGenelBagis = (Spinner)findViewById(R.id.spinner2);
dataAdapterForGenelBagis = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,aylar);
spinnerGenelBagis.setAdapter(dataAdapterForGenelBagis);
mText = (TextView)findViewById(R.id.textView16);
spinnerGenelBagis.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
RadioGroup radioGroup = (RadioGroup) findViewById(R.id.radioGroup1);
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
RadioButton meslekLisesiButton = (RadioButton) findViewById(R.id.meslekLisesi);
RadioButton yuksekOgrenimButton = (RadioButton) findViewById(R.id.yuksekOgrenim);
RadioButton yuksekLisansButton = (RadioButton) findViewById(R.id.meslekLisesi);
RadioButton doktoraButton = (RadioButton) findViewById(R.id.meslekLisesi);
String text = spinnerGenelBagis.getSelectedItem().toString();
int month = Integer.parseInt(text);
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
if (meslekLisesiButton.isChecked() == true) {
String amount = Integer.toString(month * 200);
mText.setText(amount);
} else if (yuksekOgrenimButton.isChecked() == true) {
//
} else if (yuksekLisansButton.isChecked() == true) {
//
} else if (doktoraButton.isChecked() == true) {
//
}
}
});
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
}}
xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.merve.tev.GenelBagis"
tools:layout_editor_absoluteY="81dp"
tools:layout_editor_absoluteX="0dp">
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:text="Burs Vermek İstediğiniz Toplam Tutar"
tools:layout_constraintTop_creator="1"
android:layout_marginTop="22dp"
app:layout_constraintTop_toBottomOf="@+id/spinner2"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginLeft="16dp" />
<RadioGroup
android:id="@+id/radioGroup1"
android:layout_width="279dp"
android:layout_height="130dp"
android:checkedButton="@+id/meslekLisesi"
tools:layout_constraintTop_creator="1"
tools:layout_constraintBottom_creator="1"
android:layout_marginStart="16dp"
app:layout_constraintBottom_toBottomOf="@+id/spinner2"
android:layout_marginTop="92dp"
tools:layout_constraintLeft_creator="1"
android:layout_marginBottom="92dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginLeft="16dp">
<RadioButton
android:id="@+id/meslekLisesi"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Meslek Lisesi (Aylık) 200 TL" />
<RadioButton
android:id="@+id/yuksekOgrenim"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Yüksek Öğrenim (Aylık) 510 TL"
tools:layout_editor_absoluteX="42dp"
tools:layout_editor_absoluteY="169dp" />
<RadioButton
android:id="@+id/yuksekLisans"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Yüksek Lisans (Aylık) 850 TL" />
<RadioButton
android:id="@+id/doktora"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Doktora (Aylık) 1150 TL" />
</RadioGroup>
<Spinner
android:id="@+id/spinner2"
android:layout_width="310dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
tools:layout_constraintTop_creator="1"
android:layout_marginTop="26dp"
app:layout_constraintTop_toBottomOf="@+id/textView15"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginLeft="16dp" />
<Button
android:id="@+id/devamEt2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textAllCaps="false"
android:textSize="15sp"
android:text="Devam Et"
style="@style/Widget.AppCompat.Button.Colored"
tools:layout_constraintRight_creator="1"
tools:layout_constraintBottom_creator="1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="@+id/textView16"
tools:layout_constraintLeft_creator="1"
android:layout_marginBottom="43dp"
app:layout_constraintLeft_toLeftOf="@+id/textView16" />
<TextView
android:id="@+id/textView13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Öğrenci Eğitim Düzeyine Göre Bağış"
tools:layout_constraintTop_creator="1"
tools:layout_constraintBottom_creator="1"
app:layout_constraintBottom_toTopOf="@+id/radioGroup1"
android:layout_marginStart="16dp"
android:layout_marginTop="46dp"
tools:layout_constraintLeft_creator="1"
android:layout_marginBottom="29dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginLeft="16dp" />
<TextView
android:id="@+id/textView15"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Kaç Aylık Burs Vermek İstersiniz?"
tools:layout_constraintTop_creator="1"
tools:layout_constraintBottom_creator="1"
android:layout_marginStart="16dp"
app:layout_constraintBottom_toBottomOf="parent"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginLeft="16dp" />
<TextView
android:id="@+id/textView16"
android:layout_width="89dp"
android:layout_height="29dp"
tools:layout_constraintTop_creator="1"
tools:layout_constraintBottom_creator="1"
android:layout_marginStart="16dp"
app:layout_constraintBottom_toBottomOf="@+id/devamEt2"
android:layout_marginTop="64dp"
app:layout_constraintTop_toBottomOf="@+id/spinner2"
tools:layout_constraintLeft_creator="1"
android:layout_marginBottom="61dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginLeft="16dp" />
</android.support.constraint.ConstraintLayout>