#java #android #android-edittext #android-radiobutton
#java #Android #android-edittext #android-radiobutton
Вопрос:
Я разрабатываю регистрационную форму, в которой у меня есть одно поле EditText для категорий. Этот список категорий открывается как радиогруппа в отдельном всплывающем окне, когда мы щелкаем в поле EditText. Он работает нормально до всплывающего окна. Однако я не могу вернуть значение обратно в поле EditText после выбора кнопки RadioButton во всплывающем действии.
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>
Ответ №1:
Вы можете просто попробовать использовать объект SharedPreference …. сохраните данные в своем объекте sharedpreference при нажатии переключателя и получите данные из sharedpreference там, где вы хотите.
Если вы поделитесь кодом, я могу помочь больше.
Комментарии:
1. Спасибо за ответ. ниже приведен код и xml. .java
2. Код добавлен выше