java - Trying to add multiple views but get a blank screen -


i created custom xml file linearlayout , textview. have loop want go through arraylist , add view scrollview each object. below code tried achieve this, gives me blank screen. tried see if arraylist empty, that's not it. didn't know doing when tried this. wanted see if worked, didn't what's problem?

        for(int x = 0; x < runs.size(); x++){          inflater = getlayoutinflater();         view layout = inflater.inflate(r.layout.run_layout, (viewgroup) getcurrentfocus());          textview name = (textview) layout.findviewbyid(r.id.tvrunname);         name.settext(runs.get(x).getname());          llruns.addview(layout);     } 

heres run_layout xml....

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:background="@drawable/run_background" >  <textview     android:id="@+id/tvrunname"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:textcolor="@android:color/white"     android:textappearance="?android:attr/textappearancemedium"     android:layout_gravity="center"     android:layout_margintop="10dp" /> 

here's activities xml....

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".yourruns" android:background="#181818" android:id="@+id/llyourrunslayout">  <scrollview     android:id="@+id/svruns"     android:layout_width="match_parent"     android:layout_height="match_parent" >      <linearlayout         android:id="@+id/llruns"         android:layout_width="match_parent"         android:layout_height="match_parent"         android:orientation="vertical" >       </linearlayout>  </scrollview> 

change (viewgroup) getcurrentfocus() null, becouse inflater.inflate() second parameter parent of view, , when start activity default no elements focus. , indicate 2 parents view first on inflate, second when add layout llruns.

for(int x = 0; x < runs.size(); x++){      inflater = getlayoutinflater();     view layout = inflater.inflate(r.layout.run_layout, (viewgroup) getcurrentfocus());      textview name = (textview) layout.findviewbyid(r.id.tvrunname);     name.settext(runs.get(x).getname());      llruns.addview(layout); } 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -