En android SetText sólo toma resId

Esto es probablemente súper simple, pero estoy teniendo problemas con el settext en el desarrollo de Android.

El código siguiente:

TextView countDownTextView = FindViewById<TextView> (Resource.Id.countdownTimer); countDownTextView.SetText ("New text"); 

Da los errores:

 The best overloaded method match for 'Android.Widget.TextView.SetText(int)' has some invalid arguments Argument 1: cannot convert from 'string' to 'int' 

Ahora settext debería ser (string) pero por alguna razón cuando lo escribo, quiere que int rest. ¿Cómo cambio la Textview con settext y una cadena?

He intentado usar un

 string value ="new text" 

Pero eso tampoco funcionó.

Hecho una versión más simple, pero obtener el mismo problema

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

Y el 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> 

Si está usando Xamarin:

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

Considere este código

 String value = "New Text"; TextView countDownTextView = (TextView)findViewById(R.id.countdownTimer); countDownTextView.SetText (value); 

Solo cambia así y prueba

  TextView countDownTextView = (TextView)findViewById (R.Id.countdownTimer); countDownTextView.SetText("New text"); 

Intente cambiar su código a:

 TextView countDownTextView = (TextView) findViewById( R.id.countdownTimer ); countDownTextView.setText( "New text" ); 

Preste atención a la diferencia de mi código con el suyo.

Usted está recibiendo el componente incorrecto y además está llamando a los métodos en el camino equivocado. La letra "F" en findViewById no debe ser mayúscula sino minúscula. Lo mismo se aplica al ID de recursos y al interior de los paréntesis.

  • Comunicación entre 2 aplicaciones en el mismo dispositivo iOS / Android con Xamarin
  • Toma la foto falla en los teléfonos Samsung
  • Visual Studio y Android Device Monitor no detectan ningún dispositivo
  • Xamarin aplicaciones son grandes por qué y pueden ser más pequeños
  • Los archivos XAML.g.cs generados automáticamente no se pueden compilar en el proyecto PCL Xamarin Forms
  • Xamarin Forms Android App Crashes ejecutando Debug con VS Android emulador
  • ¿Hay posibilidad de asignar un valor a Android Button en Xamarin?
  • Monodroid - Manejo de eventos en las vistas secundarias de filas ListView reutilizadas
  • Cómo determinar el tipo MIME de archivo en android?
  • Nativo de Google Plus Login para Xamarin.Android y Xamarin.iOS
  • Cómo conectar y enviar datos con bluetooth c # Xamarin?
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.