在android SetText中只需要resId

use*_*870 4 android xamarin

这可能非常简单,但我在android开发中遇到了settext问题.

以下代码:

TextView countDownTextView = FindViewById<TextView> (Resource.Id.countdownTimer);

countDownTextView.SetText ("New text");
Run Code Online (Sandbox Code Playgroud)

给出错误:

The best overloaded method match for 'Android.Widget.TextView.SetText(int)' has some invalid arguments

Argument 1: cannot convert from 'string' to 'int'
Run Code Online (Sandbox Code Playgroud)

现在settext应该是(字符串)但是由于某种原因,当我编写它时,它需要int残余.如何使用settext和字符串更改Textview?

我试过用过

string value ="new text"
Run Code Online (Sandbox Code Playgroud)

但那也没有用.

制作一个更简单的版本,但得到同样的问题

using System;

using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;

namespace CountdownTest
{
    [Activity (Label = "CountdownTest", MainLauncher = true)]
    public class MainActivity : Activity
    {
    int count = 1;

    protected override void OnCreate (Bundle bundle)
    {
        base.OnCreate (bundle);

        // Set our view from the "main" layout resource
        SetContentView (Resource.Layout.Main);

        // Get our button from the layout resource,
        // and attach an event to it
        Button button = FindViewById<Button> (Resource.Id.myButton);

        button.Click += delegate {
            button.Text = string.Format ("{0} clicks!", count++);
        };

        TextView textV = (TextView)FindViewById<TextView> (Resource.Id.CallText);

        textV.SetText ("diverse");
    }
}
}
Run Code Online (Sandbox Code Playgroud)

和XML

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <Button
        android:id="@+id/myButton"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />
    <TextView
        android:text="Text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/CallText" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

Sta*_*tam 7

如果您使用的是Xamarin:

TextView countDownTextView = FindViewById<TextView> (Resource.Id.countdownTimer);

countDownTextView.Text = "value";
Run Code Online (Sandbox Code Playgroud)