Sé que es posible agregar algunos diseños como Button
y a LinearLayout
. Quiero crear más de uno TextView
según la condición de un ciclo for.Cómo agregar múltiples dinámicas de TextView a la definición LinearLayout en main.xml
Lo he intentado a mi manera, pero no puedo crearlo. ¿Alguien sabe cómo crearlo?
El bucle for será diferente en función de la condición. Por favor ayúdenme con respecto a esto. ¿Es posible crear la matriz de TextView
?
Ya he expuesto el diseño con
setContentView(R.layout.result_page);
estoy usando funciones para añadir ese punto de vista a mi vista existente:
La función es:
public void addAll()
{
LinearLayout layout = (LinearLayout)findViewById(R.id.myLayout);
layout.setOrientation(1);
TextView name[] = null;
TextView website[] = null;
TextView category[] = null;
for (int i = 0; i < 5; i++)
{
name[i] = new TextView(this);
name[i].setText("Name = Shreyash");
website[i] = new TextView(this);
website[i].setText("Website = shreyah.co.cc");
category[i] = new TextView(this);
category[i].setText("Website Category = OWN");
layout.addView(name[i]);
layout.addView(website[i]);
layout.addView(category[i]);
}
}
Pero después que si ejecuto la aplicación, me muestra un error como:
09-08 11:03:28.755: ERROR/AndroidRuntime(318): FATAL EXCEPTION: main
09-08 11:03:28.755: ERROR/AndroidRuntime(318): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.quiz.spellingquiz/com.quiz.spellingquiz.ResultDisplayPage}: java.lang.NullPointerException
09-08 11:03:28.755: ERROR/AndroidRuntime(318): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
09-08 11:03:28.755: ERROR/AndroidRuntime(318): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
09-08 11:03:28.755: ERROR/AndroidRuntime(318): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
09-08 11:03:28.755: ERROR/AndroidRuntime(318): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
09-08 11:03:28.755: ERROR/AndroidRuntime(318): at android.os.Handler.dispatchMessage(Handler.java:99)
09-08 11:03:28.755: ERROR/AndroidRuntime(318): at android.os.Looper.loop(Looper.java:123)
09-08 11:03:28.755: ERROR/AndroidRuntime(318): at android.app.ActivityThread.main(ActivityThread.java:4627)
09-08 11:03:28.755: ERROR/AndroidRuntime(318): at java.lang.reflect.Method.invokeNative(Native Method)
09-08 11:03:28.755: ERROR/AndroidRuntime(318): at java.lang.reflect.Method.invoke(Method.java:521)
09-08 11:03:28.755: ERROR/AndroidRuntime(318): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-08 11:03:28.755: ERROR/AndroidRuntime(318): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-08 11:03:28.755: ERROR/AndroidRuntime(318): at dalvik.system.NativeStart.main(Native Method)
09-08 11:03:28.755: ERROR/AndroidRuntime(318): Caused by: java.lang.NullPointerException
09-08 11:03:28.755: ERROR/AndroidRuntime(318): at com.quiz.spellingquiz.ResultDisplayPage.addAll(ResultDisplayPage.java:59)
09-08 11:03:28.755: ERROR/AndroidRuntime(318): at com.quiz.spellingquiz.ResultDisplayPage.onCreate(ResultDisplayPage.java:34)
09-08 11:03:28.755: ERROR/AndroidRuntime(318): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-08 11:03:28.755: ERROR/AndroidRuntime(318): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
09-08 11:03:28.755: ERROR/AndroidRuntime(318): ... 11 more
No sé dónde estoy equivocado.
por favor ayúdenme con respecto a esto.
me dieron el resultado con código de Deev así:
Pero quiero fijar la Palabra bajo la palabra de la etiqueta, y la respuesta debajo de la respuesta de la etiqueta. Pero, ¿cómo es posible? Creo que tengo que establecer otro LinearLayout para eso. ¿Puede alguien decirme cómo configuro otro LinearLayout para ese tipo de apariencia?
Publique su código hasta el momento – Jack
Agregue un código de ejemplo para mostrar lo que ya ha intentado. Esto nos ayudará a ver lo que no funciona. – elevine
@Jack: por favor vea mi pregunta actualizada. –