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

标签 java android android-edittext android-radiobutton

我正在设计一个注册表单,其中有一个用于类别的 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/

相关文章:

java - Wildfly 8 : Not able to deploy Jolokia running at different port w. r.t同一IP下的其他应用程序

java - Log4j2 不滚动文件,而是在 SizeBasedTriggeringPolicy 之后覆盖同一文件

android - 如何在 android 平台上的可执行文件中使用 CallStack(在 CallStack.tpp 中)?

java - 如何在编辑文本聚焦时显示软键盘

java - Hibernate - 如何在 JSP 表中显示对象列表?

java - 尝试导航到上一个 Activity 时 Intent 崩溃

android - 禁用后启用 Edittext

android - 如何在我的自定义 styles.xml 中继承默认的 Android 样式?

android - 如何找出apk文件中使用的Jar?

android - 如何通过 gradle 任务在设备上安装和运行 Android 应用程序?