This is probably very simple, but I have problems with settext in android development.
The following code:
TextView countDownTextView = FindViewById<TextView> (Resource.Id.countdownTimer);
countDownTextView.SetText ("New text");
gives 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 the settext should be (string), but for some reason, when I write it, it wants the int to remain. How to change a textview using only settext and string?
I tried to use
string value ="new text"
but this also does not work.
Made a simpler version but got the same issue
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);
SetContentView (Resource.Layout.Main);
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 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>
source
share