Reputation: 3
I am designing a registration form where I have one EditText field for Categories. This list of categories is opened as a radio group in separate Popup activity when we click in EditText field. It is working fine till popup. However, I am not able to get the value back in the EditText field after selecting the RadioButton in the Popup activity.
Activity.java
import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.TextView;
import java.security.PublicKey;
public class Industry extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate ( savedInstanceState );
setContentView ( R.layout.activity_industry );
DisplayMetrics dm = new DisplayMetrics ();
getWindowManager ().getDefaultDisplay ().getMetrics ( dm );
int width = dm.widthPixels;
int height = dm.heightPixels;
getWindow ().setLayout ( (int)(width*.9),(int)(height*.85) );
WindowManager.LayoutParams params = getWindow ().getAttributes ();
params.gravity = Gravity.CENTER;
params.x = 0;
params.y = -20;
getWindow ().setAttributes ( params );
}
}
.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=".Industry">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RadioGroup
android:id="@+id/rbtnGroupIndus"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RadioButton
android:id="@+id/rdbtnind1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Agriculture And Allied Industries"
android:onClick="selectID"
/>
<RadioButton
android:id="@+id/rdbtnind2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Automobiles"
android:onClick="selectID"
/>
<RadioButton
android:id="@+id/rdbtnind3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Auto Components"
android:onClick="selectID"
/>
<RadioButton
android:id="@+id/rdbtnind4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Aviation"
android:onClick="selectID"
/>
<RadioButton
android:id="@+id/rdbtnind5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Banking"
android:onClick="selectID"
/>
<RadioButton
android:id="@+id/rdbtnind6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Cement"
android:onClick="selectID"
/>
<RadioButton
android:id="@+id/rdbtnind7"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Consumer Durables"
android:onClick="selectID"
/>
<RadioButton
android:id="@+id/rdbtnind8"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Ecommerce"
android:onClick="selectID"
/>
<RadioButton
android:id="@+id/rdbtnind9"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Education And Training"
android:onClick="selectID"
/>
<RadioButton
android:id="@+id/rdbtnind10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Engineering And Capital Goods"
android:onClick="selectID"
/>
<RadioButton
android:id="@+id/rdbtnind11"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Financial Services"
android:onClick="selectID"
/>
<RadioButton
android:id="@+id/rdbtnind12"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Fmcg"
android:onClick="selectID"
/>
<RadioButton
android:id="@+id/rdbtnind13"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Gems And Jewellery"
android:onClick="selectID"
/>
<RadioButton
android:id="@+id/rdbtnind14"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Healthcare"
android:onClick="selectID"
/>
<RadioButton
android:id="@+id/rdbtnind15"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Infrastructure"
android:onClick="selectID"
/>
<RadioButton
android:id="@+id/rdbtnind16"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Insurance"
android:onClick="selectID"
/>
<RadioButton
android:id="@+id/rdbtnind17"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="It / Ites"
android:onClick="selectID"
/>
<RadioButton
android:id="@+id/rdbtnind18"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Manufacturing"
android:onClick="selectID"
/>
<RadioButton
android:id="@+id/rdbtnind19"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Media And Entertainment"
android:onClick="selectID"
/>
<RadioButton
android:id="@+id/rdbtnind20"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Metals And Mining"
android:onClick="selectID"
/>
<RadioButton
android:id="@+id/rdbtnind21"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Oil And Gas"
android:onClick="selectID"
/>
<RadioButton
android:id="@+id/rdbtnind22"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Pharmaceuticals"
android:onClick="selectID"
/>
<RadioButton
android:id="@+id/rdbtnind23"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Ports"
android:onClick="selectID"
/>
<RadioButton
android:id="@+id/rdbtnind24"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Power"
android:onClick="selectID"
/>
<RadioButton
android:id="@+id/rdbtnind25"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Railways"
android:onClick="selectID"
/>
<RadioButton
android:id="@+id/rdbtnind26"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Real Estate"
android:onClick="selectID"
/>
<RadioButton
android:id="@+id/rdbtnind27"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Renewable Energy"
android:onClick="selectID"
/>
<RadioButton
android:id="@+id/rdbtnind28"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Retail"
android:onClick="selectID"
/>
<RadioButton
android:id="@+id/rdbtnind29"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Roads"
android:onClick="selectID"
/>
<RadioButton
android:id="@+id/rdbtnind30"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Science And Technology"
android:onClick="selectID"
/>
<RadioButton
android:id="@+id/rdbtnind31"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Services"
android:onClick="selectID"
/>
<RadioButton
android:id="@+id/rdbtnind32"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Steel"
android:onClick="selectID"
/>
<RadioButton
android:id="@+id/rdbtnind33"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Telecommunications"
android:onClick="selectID"
/>
<RadioButton
android:id="@+id/rdbtnind35"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Tourism And Hospitality"
android:onClick="selectID"
/>
</RadioGroup>
</ScrollView>
</android.support.constraint.ConstraintLayout>
Upvotes: 0
Views: 69
Reputation: 305
You can simply try with using SharedPreference object.... save the data in your sharedpreference object on Radio Button Click and get data from sharedpreference where you want.
If you share the code I can help more.
Upvotes: 2