2016-05-12 14 views
0

私はC#とXamarinの新機能ですが、私はこの解決策を間違って行っているかもしれませんが、ユーザ入力0-10の数値ではなく、負の数値ではない小数点以下の値を宣言しています。それは基本的な算術演算a/b * c =答えを行います...私はvar C(答え)を表示し、それを使用して最終的にタイマー間隔を変更します。しかし、今のところ、コードを自分のテキストを表示するためのテキストとして表示するのは苦労しています....下のコードを見てください。C#Xamarinでの計算、答えを表示する。

[Activity(Label = "Infusion Calculator")] 
public class infusionact : Activity 
{ 
    protected override void OnCreate(Bundle bundle) 
    { 
     base.OnCreate(bundle); 

     SetContentView(Resource.Layout.Infusion); 
     // Create your application here 
     var volume = FindViewById<EditText>(Resource.Id.boxvolume); 
     var drip = FindViewById<EditText>(Resource.Id.boxdrip); 
     var dripmins = FindViewById<EditText>(Resource.Id.boxmins); 
     var answermins = (Resource.Id.boxvolume/Resource.Id.boxmins * Resource.Id.boxdrip); 

     Button button = FindViewById<Button>(Resource.Id.btncalculate); 
     TextView textView1 = (TextView)FindViewById(Resource.Id.textView1); 

     button.Click += delegate 
     { 
      // NEED TO FIGURE OUT HOW TO SET TXT LABEL WITH VAR ANSWERMINS ON CLICK 
      textView1.SetText(answermins); 

     }; 



    } 

} 

答えて

1

あなたはこれらの変数を誤って使用していると思います。例えば、

var volume = FindViewById<EditText>(Resource.Id.boxvolume); 

var volumeValue = volume.Text; 

が戻ってくる、一方で、指定したIDに関連付けられたVIEWを返しvalueあなたのEditText制御のための入力として入力されています。これらの値は処理してからTextViewに表示する必要があります。

0

リソースIDを使用しているため、EditTextの値ではなく計算を行うため、行を削除してください。

var answermins = (Resource.Id.boxvolume/Resource.Id.boxmins * Resource.Id.boxdrip); 

計算を行うためにclickイベントを更新します。

button.Click += delegate 
    { 
     var volumeValue = 0; 
     var dripValue = 0; 
     var dripMinsValue = 0; 

     // Parse value in text to integer 
     int.TryParse(volume.Text, out volumeValue); 
     int.TryParse(drip.Text, out dripValue); 
     int.TryParse(dripmins.Text, out dripMinsValue); 

     var answermins = 0; 
     if (dripMinsValue != 0) 
     { 
      answermins = volumeValue/dripMinsValue * dripValue; 
     } 

     textView1.SetText(answermins); 
    }; 
0

これが正しいコードである -

[Activity(Label = "Infusion Calculator")] 
public class infusionact : Activity 
{ 
protected override void OnCreate(Bundle bundle) 
{ 
    base.OnCreate(bundle); 

    SetContentView(Resource.Layout.Infusion); 
    // Create your application here 
    var volume = FindViewById<EditText>(Resource.Id.boxvolume); 
    var drip = FindViewById<EditText>(Resource.Id.boxdrip); 
    var dripmins = FindViewById<EditText>(Resource.Id.boxmins); 

    Button button = FindViewById<Button>(Resource.Id.btncalculate); 
    TextView textView1 = FindViewById<TextView>(Resource.Id.textView1); 

    button.Click += delegate 
    { 
     // NEED TO FIGURE OUT HOW TO SET TXT LABEL WITH VAR ANSWERMINS ON CLICK 
     var answermins = volume.Text/(dripmins.Text*drip.Text); 
      textView1.Text=answermins.ToString(); 

    }; 



} 
} 
関連する問題