gpt4 book ai didi

java - 如何从弹出 Activity 中的单选组获取编辑文本中的值?

转载 作者:行者123 更新时间:2023-12-02 01:33:36 25 4
gpt4 key购买 nike

我正在设计一个注册表单,其中有一个用于类别的 EditText 字段。当我们单击 EditText 字段时,此类别列表将在单独的 Popup Activity 中作为单选组打开。在弹出窗口之前它工作正常。但是,在 Popup Activity 中选择 RadioButton 后,我无法在 EditText 字段中取回值。

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>

最佳答案

您可以简单地尝试使用 SharedPreference 对象....将数据保存在单选按钮单击上的共享首选项对象中,并从您想要的共享首选项获取数据。

如果您分享代码,我可以提供更多帮助。

关于java - 如何从弹出 Activity 中的单选组获取编辑文本中的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55618293/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com