[英]How to get an EditText value to go from one activity to another as an int
[英]How to get value in edittext from a Radio Groups in Popup Activity?
我正在設計一個注冊表,其中有一個“類別”的EditText字段。 當我們單擊EditText字段時,將在單獨的Popup活動中以單選組的形式打開此類別列表。 直到彈出窗口都可以正常工作。 但是,在Popup活動中選擇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對象。...將數據保存在單選按鈕Click上的sharedpreference對象中,並從所需的sharedpreference獲取數據。
如果您共享代碼,我可以提供更多幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.