RS wrote:
> I want to populate my UI with dynamic buttons at runtime. I am trying
> to invoke a feed from the net and based on the results (which are URLs
> pointing to image resources), i need to create buttons on the layout
> with their background set as images retrieved from URLs. I have an
> array of buttons which get instantiated based on the number of results
> returned. I was wondering whats the best way to do it - as writing
> them on the main.xml is not feasible.

1. Create your ImageButton via an appropriate constructor (e.g., new
ImageButton(this);)

2. Configure the ImageButton with the desired image (e.g., setImageBitmap())

3. Add the ImageButton to some container via addView(), supplying a
suitable LayoutParams object (e.g., LinearLayout.LayoutParams) to
configure where the button should appear

4. Make sure the whole thing is in a ScrollView to deal with the
possibility that you have more buttons than the screen can hold

Or, skip the buttons and use a ListView, so you can get a UI that is
consistent with what users of other Android applications, or the iPhone,
are used to.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://twitter.com/commonsguy

Android App Developer Books: http://commonsware.com/books.html

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to