[英]How to fetch text from a TextView in xml file to a TexView in a custom dialog?
I have a TextView in my .xml file
and below that TextView I have a button. 我的
.xml file
有一个TextView,在该TextView下方,我有一个按钮。 The text in TextView changes everytime when the app is running. 每当应用程序运行时,TextView中的文本都会更改。 I created a custom dialog so that when I press the button the custom dialog shows.
我创建了一个自定义对话框,以便在按下按钮时显示自定义对话框。 In this custom dialog I also have a TextView and I want this TextView to take and dislplay data that is in my main TextView.
在此自定义对话框中,我还具有一个TextView,并且我希望该TextView可以获取和显示主TextView中的数据。
Here is my main.xml file
这是我的
main.xml file
<TextView
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/country"
android:layout_marginTop="10dp"
android:text="country"/>
And this is TextView in custom_dialog.xml file
这是
custom_dialog.xml file
TextView
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/get_country"
android:text=""/>
Below is my MainActivity.class
custom dialog in onCreate()
以下是
onCreate()
我的MainActivity.class
自定义对话框
customDialog= new Dialog( this );
customDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
customDialog.setContentView(R.layout.custom_dialog);
customDialog.setCancelable( true );
TextView textContry=(TextView)customDialog.findViewById(R.id.get_country);
I need this TextView in custom_dialog
to take data in TextView of main.xml
when the dialog shows. 对话框显示时,我需要
custom_dialog
此TextView来获取main.xml
TextView中的数据。
您必须在自定义对话框textView中设置文本,方法是单击按钮时从主文本视图中获取文本。
textContry.setText(textviewMain.getText().toString());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.