2012-02-28 16 views
8

Estoy tratando de hacer un brindis en secuencia para mostrar una fuente rss ruuning. Estoy recibiendo el siguiente error cuando se ejecuta: java.lang.RuntimeException: Este pan tostado no fue creado con Toast.makeText()error al mostrar tostadas

Mi código es:

LayoutInflater inflater = getLayoutInflater(); 
View layout = inflater.inflate(R.layout.toast_layout, 
           (ViewGroup) findViewById(R.id.toast_layout_root)); 

ImageView image = (ImageView) layout.findViewById(R.id.toastimage); 
image.setImageResource(R.drawable.bball_icon); 
TextView text = (TextView) layout.findViewById(R.id.toasttext); 

Toast toast = new Toast(getApplicationContext()); 
toast.setView(layout); 
for (int i=0;i<episode_titles.size();i++) 
{ 
    toast.setText(episode_titles.get(i).toString()); 
    toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0); 
    toast.setDuration(Toast.LENGTH_SHORT); 

    toast.show(); 

} 
+0

¿Se puede publicar el logcat de su error? – caiocpricci2

+0

02-28 11: 11: 10.421: E/AndroidRuntime (9715): java.lang.RuntimeException: Esta tostada no se creó con Toast.makeText() – user1163234

+0

En realidad, necesitamos el logcat que se refiere al error real, usted mencionó ejecutar : java.lang.RuntimeException! – caiocpricci2

Respuesta

2

La tostada U puede especificar como esto .. .

Toast.makeText(getApplicationContext(), "hai", Toast.LENGTH_LONG).show(); 

Entonces u puede escribir así ...

 String s=episode_titles.get(i).toString(); 
     Toast.makeText(getApplicationContext(), "UrMessage:"+s, Toast.LENGTH_LONG).show(); 
+0

necesita una vista personalizada ... – user1163234

1
Toast.makeText(getApplicationContext(), "your text", Toast.LENGTH_LONG).show(); 

Me funciona.

+0

necesita una vista personalizada ... – user1163234

2

Se puede usar esta

for (int i=0;i<episode_titles.size();i++) 
{ 
    Toast.makeText(getApplicationContext(), episode_titles.get(i).toString(), Toast.LENGTH_LONG).show(); 
} 
+0

Quiero usar una vista personalizada ... – user1163234

0

Try esto fuera:

LayoutInflater inflater = getLayoutInflater(); 
View layout = inflater.inflate(R.layout.toast_layout, 
           (ViewGroup) findViewById(R.id.toast_layout_root)); 

ImageView image = (ImageView) layout.findViewById(R.id.toastimage); 
image.setImageResource(R.drawable.bball_icon); 
TextView text = (TextView) layout.findViewById(R.id.toasttext); 

Toast toast = new Toast(getApplicationContext()); 
toast.setView(layout); 
for (int i=0;i<episode_titles.size();i++) 
{ 
    text.setText(episode_titles.get(i).toString()); 
    toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0); 
    toast.setDuration(Toast.LENGTH_SHORT); 

    toast.show(); 

} 

Avísame si esto funciona :)

+0

Estoy obteniendo solo el resultado final de la matriz y no la totalidad ... – user1163234

0
Toast toast = new Toast(getApplicationContext()); 
//your for loop here { 
     toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0); 
     toast.setDuration(Toast.LENGTH_LONG); 
     TextView txt1 = new TextView(this); 
     txt1.setText(R.string.hello); 
     toast.setView(txt1); 
     toast.show(); 
    } 
+0

No entiendo ... – user1163234

+1

No es posible agregar texto directamente, – Sandy09

+0

@Andhrudu Sí, lo es. Mira mi respuesta. – sandalone

14

Para ajustar el texto a la tostada, hay que inicializarlo a través makeText.

De esta manera:

Toast toast = Toast.makeText(this, "message", Toast.LENGTH_SHORT); 
    toast.setText("new message"); 
    toast.setGravity(Gravity.CENTER, 0, 0); 
    //other setters 
    toast.show(); 
1

En lugar de toast.setText(episode_titles.get(i).toString());, utilice text.setText();.