multithreading - Android: Inflating layout takes to long -


found solution!

i use viewpager instead of viewflipper. views generated within run() method (which there because fetch data web) , saveed in map. in handler call pageradapter.notifydatasetchanged() pageradapter uses map of views , works smooth , fast. i'm looking away have viewpager scroll endless, thats problem not connected 1 ;)

thank of answers , keep support.

i'm quite new android development , facing problem while inflating (huge) layout. getting data webservice works fine i'm using handler within activity bring data frontend. here handlemessage:

    public void handlemessage(message msg) {         layoutinflater inflater = getlayoutinflater();          list<integer> gamedays = new arraylist<integer>(games.keyset());         collections.sort(gamedays);          (integer gameday : gamedays) {              view gamedaytable = inflater.inflate(r.layout.gamedaytable, null);             tablelayout table = (tablelayout) gamedaytable.findviewbyid(r.id.gamedaytable);             table.removeallviews();             list<game> gamelist = games.get(gameday);             int rowcount = 2;             (game game : gamelist) {                  view tablerow = inflater.inflate(r.layout.gamedayrow, null);                  textview hometeam = (textview) tablerow.findviewbyid(r.id.gamedayhome);                 textview awayteam = (textview) tablerow.findviewbyid(r.id.gamedayaway);                 textview gameresult = (textview) tablerow.findviewbyid(r.id.gamedayresult);                 gameresult.setbackgroundresource(r.drawable.resultbackground);                 hometeam.settext(game.gethometeam().getname());                 awayteam.settext(game.getawayteam().getname());                 if (game.gethomegoals() < 0 || game.getawaygoals() < 0) {                     gameresult.settext("-:-");                 } else {                     gameresult.settext(game.gethomegoals() + ":" + game.getawaygoals());                 }                  if (rowcount % 2 == 0) {                     tablerow.setbackgroundcolor(0xffdee0dd);                  } else {                     // setting alternative background                     tablerow.setbackgroundcolor(0xfff1f3f0);                 }                 rowcount++;                  table.addview(tablerow);             }             flipper.addview(gamedaytable);         }         flipper.setdisplayedchild(thisgameday - 1);         pd.dismiss();      } 

my problem code runs quite slow , d processdialog freezes 1 second before disappears , layout shown. games consists of 34 entries contains 9 entries itself. i'm adding 34 views consisting of relativelayout () holds table think problem is, android starts draw , calculte layout , takes long. if i'm correct can not use asyntask because can not ui stuff there , im doing ui stuff only.

i looking way have process dialog not freezing while doing this. or maybe i'm doing completly wrong

r.layout.gamedaytable:

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/relativelayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#fff1f3f0" android:focusableintouchmode="false" >  <tablelayout     android:id="@+id/gamedaytable"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_centerhorizontal="true"     android:layout_centervertical="true"     android:focusableintouchmode="false" > </tablelayout>  </relativelayout> 

r.layout.gamedayrow:

<tablerow xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/tablerow1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:focusableintouchmode="false" android:paddingbottom="5dp" android:paddingtop="5dp" >  <textview     android:id="@+id/gamedayhome"     style="@style/textsizesmallscreen"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_marginleft="5dp"     android:text="mannschaft 1" />  <textview     android:id="@+id/textview2"     style="@style/textsizesmallscreen"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:paddingleft="10dp"     android:paddingright="10dp"     android:text=":" />  <textview     android:id="@+id/gamedayaway"     style="@style/textsizesmallscreen"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:text="mannschaft 2" />  <textview     android:id="@+id/gamedayresult"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_marginleft="10dp"     android:layout_marginright="5dp"     android:background="@drawable/resultbackground"     android:paddingleft="10dip"     android:text="0:5"     android:textcolor="#ffffff"     android:textsize="11dp"     android:textstyle="bold"     android:typeface="monospace" />  </tablerow> 

additional info: how table should like. i'm not sure if should listview because me tabledata ;)

table

you seem building list, should @ using listview, which'll have advantages of needing build ui number of rows being shown, , view re-use, don't need inflate many rows.


Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -