There that may explain any stupidity that is to follow!
Problem:
From main app screen I click a button that takes me to a new screen (separate Activity/Intent)
This new screen immediately displays three local content buttons and spawns a new thread that starts loading online images to be used for dynamic buttons... ( Don't freak out, I AM using a Handler
)I see the 3 local buttons immediately but the online buttons are not shown one at a time as they are loaded (I see progress in Logcat), but are all shown at the end after the last one has been loaded.
More Info:
Layout.xml description in pseudo code
- Code: Select all
<scroll view>
<relative layout>
<table>
<table row>
<local content button 1>
<local content button 2>
<local content button 3>
</close all>
onCreate sets content view to R.Layout.xml
calls a function that sets button backgrounds and onClickListeners etc.
AND does this:
- Code: Select all
new OnlineContentThread(asyncRefresh).start();
And here's the sub class def
- Code: Select all
private class OnlineContentThread extends Thread {
Handler handler;
public OnlineContentThread(Handler h) {
handler = h;
}
public void run(){
Log.d(TAG, "Running ASYNC THREAD!");
//Check if we're online
ONLINE = Client.checkConnectivity(activity);
if ( !ONLINE ) offlinePrompt();
else {
//Connect to airosgroup.com and get available APPETIZERS content
contentList = Client.listFiles( getString(CATEGORY) );
Message msg;
Bundle bundle;
for (String[] i:contentList){
bundle = new Bundle();
bundle.putStringArray("CONTENT", i);
msg = handler.obtainMessage();
msg.setData(bundle);
handler.sendMessage(msg);
}
}
}
}
And here's the handler def:
- Code: Select all
Handler asyncRefresh = new Handler(){
public void handleMessage(Message msg){
Bundle threadBundle = msg.getData();
content = threadBundle.getStringArray("CONTENT");
drawDynamicContent(content);
}
};
Now here's explanation of drawDynamicContent(content); because it's super long and confusing, even to me and I wrote it...
content is just a string URL pointing to images to be used
drawDynamicContent(content) creates a new tableRow under the table defined in Layout.xml that already has 1 row with 3 buttons in it. I only create a new row once every 3 buttons (using global couter)
Then I create a new imageButton
take the string URL and call Client.createDrawableFromUrl(url) that return Drawable object. I take this Drawable and set it as a background for the button.
define onClick function
do TableRow.adView(button)
Again once every 3 buttons I to table.adView(tableRow)
Question:
Why do all buttons show up in the end and not as they are loaded.
Or at least one row at the time, since I don't do the table.addView every time
I tried using .invalidate() on buttons, tableRows and table but no luck.
I don't even know what .invalidate() does but I seen it in plusminus' pizza timer example and thought it may apply in my case
Any insight would be greatly appreciated.
Cheers!



