Foros del Web » Programando para Internet » Android »

problema con addView

Estas en el tema de problema con addView en el foro de Android en Foros del Web. Hola tengo este code que deberia cambiar el valor de un textview, pero no me funciona: El manifiest: @import url("http://static.forosdelweb.com/clientscript/vbulletin_css/geshi.css"); Código XML: Ver original <?xml ...
  #1 (permalink)  
Antiguo 06/06/2012, 14:10
Avatar de gilber966  
Fecha de Ingreso: abril-2010
Mensajes: 117
Antigüedad: 14 años
Puntos: 4
problema con addView

Hola tengo este code que deberia cambiar el valor de un textview, pero no me funciona:

El manifiest:
Código XML:
Ver original
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.    android:layout_width="fill_parent"
  4.    android:layout_height="fill_parent"
  5.    android:orientation="vertical"
  6.    android:id="@+id/capa1"
  7.    >
  8.  
  9.     <TextView
  10.        android:layout_width="wrap_content"
  11.        android:layout_height="wrap_content"
  12.        android:background="#01DF01"
  13.        android:textColor="#FE2E2E"
  14.        android:textSize="30sp"
  15.        android:layout_gravity="center"
  16.        android:text="hola mundo"
  17.        android:id="@+id/contenedor"
  18.         />
  19.  
  20. </LinearLayout>

Ahora el java

Código java:
Ver original
  1. package mipackage.muestra1;
  2.  
  3. import android.app.Activity;
  4. import android.os.Bundle;
  5. import android.widget.LinearLayout;
  6. import android.widget.TextView;
  7. import android.graphics.Color;
  8. public class Muestra1Activity extends Activity {
  9.     /** Called when the activity is first created. */
  10.     @Override
  11.     public void onCreate(Bundle savedInstanceState) {
  12.         super.onCreate(savedInstanceState);
  13.         setContentView(R.layout.main);
  14.         TextView contenedor=(TextView) findViewById(R.id.contenedor);
  15.         contenedor.setText("agregar este texto");
  16.         TextView nuevoContenedor=new TextView(this);
  17.         nuevoContenedor.setTextColor(Color.argb(255,0,0,0));
  18.         nuevoContenedor.setTextSize(40);
  19.         nuevoContenedor.setText("nuevo texto");
  20.         LinearLayout ll=(LinearLayout)findViewById(R.id.capa1);
  21.         ll.addView(nuevoContenedor);
  22.     }
  23.    
  24. public void print(LinearLayout ll, String texto, int size, int r, int g, int b){
  25.     TextView tv=new TextView(this);
  26.     tv.setTextColor(Color.argb(255,r,g,b));
  27.     tv.setTextSize(size);
  28.     tv.setText(texto);
  29.     ll.addView(tv);
  30.     LinearLayout l=(LinearLayout)findViewById(R.id.capa1);
  31.     print(l,"letra roja tamaño 18",18,255,0,0);
  32.     print(l,"letra verde tamaño 30",30,0,0,255);
  33. }
  34.  
  35.  
  36. }

deberian aparecer tres lineas de texto y nada

Última edición por gilber966; 06/06/2012 a las 16:02
  #2 (permalink)  
Antiguo 07/06/2012, 00:49
 
Fecha de Ingreso: junio-2012
Mensajes: 3
Antigüedad: 11 años, 10 meses
Puntos: 1
Respuesta: problema con addView

Hola. El error es que estas llamando al metodo print desde dentro
del mismo método print

Corta las siguientes lineas y copialas al final del metodo onCreate

LinearLayout l=(LinearLayout)findViewById(R.id.capa1);
print(l,"letra roja tamaño 18",18,255,0,0);
print(l,"letra verde tamaño 30",30,0,0,255);


Hecho esto ya deberia funcionar
  #3 (permalink)  
Antiguo 08/06/2012, 08:44
Avatar de gilber966  
Fecha de Ingreso: abril-2010
Mensajes: 117
Antigüedad: 14 años
Puntos: 4
Respuesta: problema con addView

Cita:
Iniciado por amarougr Ver Mensaje
Hola. El error es que estas llamando al metodo print desde dentro
del mismo método print

Corta las siguientes lineas y copialas al final del metodo onCreate

LinearLayout l=(LinearLayout)findViewById(R.id.capa1);
print(l,"letra roja tamaño 18",18,255,0,0);
print(l,"letra verde tamaño 30",30,0,0,255);


Hecho esto ya deberia funcionar
Ok voy a mirar y comento los resultados.

Etiquetas: java, apps
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 19:38.