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:
- ¿Cómo detectar los recursos no utilizados en Xamarin.Android?
- No encontró la clase "mono.android.app.Application"
- Xamarin Android deserializa el archivo json local
- El botón Atrás no responde en UrhoSharp
- Xamarin forma la posición de los elementos de la barra de herramientas para Android
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>
- Use .GetMapAsync en lugar de otro método .getMap con Google Play Services (Xamarin)
- Asegurar cadena en APK
- Eliminar listview en xamarin android
- Error al navegar lejos de una página con un mapa en Android, mientras que el teclado en pantalla es visible
- DllNotFoundException en la aplicación de Android de NDK usando Xamarin
- "Java.exe" salió con código 1 Error al ejecutar la aplicación xamarin.android
- BluetoothAdapter ActionDiscoveryFinished
- Adición de SearchView en el fragmento
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.
- ExpandableListView / Drill-Down en el menú deslizante
- Android.view.InflateException: al escribir una imagen personalizada