2016-05-13 91 views
0

我的意思是有一個應用程序,其中,我顯示一個值,並允許增加或減少它。該值可以通過「設置」活動,通過純文本字段進行更改。我的問題是關於顯示當前值作爲純文本的默認文本。純文本「文本」屬性不顯示變量的內容

這裏的設置頁面的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> 

這是我使用的值發送到設置活動代碼:

int res = 5; 
resSetButton.Click += delegate { 
    Intent ResSetAct = new Intent(this, typeof(ResourceSettingsActivity)); 
    ResSetAct.PutExtra("res", res); 
    StartActivity(ResSetAct); 
}; 

這裏是我用來獲取代碼數據在其他活動中顯示出來:

string res = Intent.GetStringExtra("res"); 
EditText CurRes = FindViewById<EditText>(Resource.Id.editCurRes); 
CurRes.Text = res; 

回答

2

純文本「文本」屬性不顯示變量的內容

因爲在這裏:

ResSetAct.PutExtra("res", res); 

傳遞int使用PutExtra但在接下來的活動嘗試開始使用它GetStringExtra

使用Intent.GetIntExtra得到int值:

int res = Intent.GetIntExtra("res");