Plain Text "Text" 属性 不显示变量的内容
Plain Text "Text" property not displaying the content of a variable
我的意思是有一个应用程序,其中,除其他外,我显示一个值并允许增加或减少它。可以通过 "settings" activity 通过纯文本字段更改此值。我的问题是关于将当前值显示为纯文本的默认文本。
这是设置页面的 XML 代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:text="Current amount:"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textCurRes"
android:layout_marginRight="0.0dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/editCurRes" />
<Button
android:text="OK"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/buttonOk" />
</LinearLayout>
这是我用来将值发送到设置的代码 activity:
int res = 5;
resSetButton.Click += delegate {
Intent ResSetAct = new Intent(this, typeof(ResourceSettingsActivity));
ResSetAct.PutExtra("res", res);
StartActivity(ResSetAct);
};
下面是我用来检索另一个 activity 中的数据并显示它的代码:
string res = Intent.GetStringExtra("res");
EditText CurRes = FindViewById<EditText>(Resource.Id.editCurRes);
CurRes.Text = res;
Plain Text “Text” property not displaying the content of a variable
因为这里:
ResSetAct.PutExtra("res", res);
使用 PutExtra
传递 int
但接下来 Activity 尝试使用 GetStringExtra
.
获取它
使用Intent.GetIntExtra
获取整型值:
int res = Intent.GetIntExtra("res");
我的意思是有一个应用程序,其中,除其他外,我显示一个值并允许增加或减少它。可以通过 "settings" activity 通过纯文本字段更改此值。我的问题是关于将当前值显示为纯文本的默认文本。
这是设置页面的 XML 代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:text="Current amount:"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textCurRes"
android:layout_marginRight="0.0dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/editCurRes" />
<Button
android:text="OK"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/buttonOk" />
</LinearLayout>
这是我用来将值发送到设置的代码 activity:
int res = 5;
resSetButton.Click += delegate {
Intent ResSetAct = new Intent(this, typeof(ResourceSettingsActivity));
ResSetAct.PutExtra("res", res);
StartActivity(ResSetAct);
};
下面是我用来检索另一个 activity 中的数据并显示它的代码:
string res = Intent.GetStringExtra("res");
EditText CurRes = FindViewById<EditText>(Resource.Id.editCurRes);
CurRes.Text = res;
Plain Text “Text” property not displaying the content of a variable
因为这里:
ResSetAct.PutExtra("res", res);
使用 PutExtra
传递 int
但接下来 Activity 尝试使用 GetStringExtra
.
使用Intent.GetIntExtra
获取整型值:
int res = Intent.GetIntExtra("res");