【问题标题】:how to type cast in mono for anddroid?如何为 android 输入单声道类型转换?
【发布时间】:2015-06-03 19:00:37
【问题描述】:

我快被这个问题发疯了。

我想将 TextView 转换为双格式,但我走的路是运行时错误。

我尝试过的方法:

 //first

var enterButton = FindViewById<Button>(Resource.Id.enterGN);
            var inPop = FindViewById<EditText>(Resource.Id.inPopulationIn);
            var goodPop = FindViewById<EditText>(Resource.Id.goodPopIn);
            var yearsNumIn = FindViewById<EditText>(Resource.Id.yearNumIn);
            var growingRate =FindViewById<EditText>(Resource.Id.growingRateIn);


            int InPop = Int32.Parse(inPop.ToString());
            int GoodPop = Int32.Parse(goodPop.ToString());
            int YearsNum = Int32.Parse(yearsNumIn.ToString());
            double GrowingRate = Int32.Parse(growingRate.ToString());



//second

var enterButton = FindViewById<Button>(Resource.Id.enterGN);
            var inPop = FindViewById<EditText>(Resource.Id.inPopulationIn);
            var goodPop = FindViewById<EditText>(Resource.Id.goodPopIn);
            var yearsNumIn = FindViewById<EditText>(Resource.Id.yearNumIn);
            var growingRate =FindViewById<EditText>(Resource.Id.growingRateIn);

            string inPops=inpop.ToString();
            string ...

            int InPop = System.Convert.ToInt32(inPops);
            int ....

请帮帮我... 错误在说:

未处理的异常:

System.FormatException: 输入字符串的格式不正确

【问题讨论】:

  • 当我进行任何类型的解析时,我都会保持一切不变,例如 double GrowingRate = double.Parse(growingRate.ToString());
  • 我修复了它,但问题没有修复它说:未处理的异常:System.FormatException:输入字符串的格式不正确
  • 您要转换的字符串的内容是什么?
  • 我尝试创建一个计算城市人口增长的应用程序。我需要将所有变量转换为 int 和 double。

标签: c# android casting mono type-conversion


【解决方案1】:

问题已经解决了^__^

EditText inPop = FindViewById<EditText>(Resource.Id.inPopulationIn);

int InPop=Int32.Parse(inPop.Text);

System.Convert.ToInt32 在 Mono for Android 中不工作,但上层代码说明如何转换您的变量。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-22
    • 1970-01-01
    • 1970-01-01
    • 2018-01-19
    • 1970-01-01
    • 2017-06-20
    相关资源
    最近更新 更多