Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In android SetText only takes resId

This is probably super simple but I am having problems with the settext in android development.

The following code:

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

countDownTextView.SetText ("New text");

gives the errors:

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

Argument 1: cannot convert from 'string' to 'int'

Now settext should be (string) but for some reason when I write it, it wants int resid. How do I change the Textview with just settext and a string?

I have tried using a

string value ="new text"

but that didnt work either.

Made a simpler version, but get the same problem

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");
    }
}
}

And the 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>
like image 241
user3729870 Avatar asked Jun 11 '14 11:06

user3729870


1 Answers

If you are using Xamarin:

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

countDownTextView.Text = "value";
like image 155
Stam Avatar answered Oct 18 '22 20:10

Stam