[android-developers] Re: Modifying the UI within Java, not XML

2009-07-12 Thread stanchat

You may want to consider the AddHeaderView and AddFooterView methods
of the list view.  The link below describes how to implement these.

http://groups.google.com/group/android-developers/browse_thread/thread/9f11fe55e35d0e9e/997e3a06ec25d745?lnk=gst&q=addHeaderView

On Jul 11, 5:58 pm, Breezy  wrote:
> So I have the basics down...  I can create a UI with the XML, I can
> show it and change the screen to another UI (another XML file) but how
> do I add to the UI?
>
> Hmmm, hard to explain...
>
> Say I have a header (just 2 textviews) that will remain at the top and
> below that is a search box and button (main.xml).  The user searches
> and I have it display the search UI (search.xml).  This UI will have
> the same header (2 textviews) and below it will have several textviews
> each one containing a search result...  Kinda like if you search for
> an app in the market.  There's no way of telling how many results
> would be returned so I figured I would have to create each textview on
> the fly within the .java file.  I'm not sure how to do this.  Most
> likely would require a loop of some sort, but whats the syntax to
> create a new textview and display it right below the one above it?
> I'm working with linear here so I would assume just creating a new
> textview it will by default go to the next one down which is what I
> want.
>
> Any help?  I searched a lot but I'm not sure what it's called that I'm
> looking for exactly.
>
> Also, say I have 30 results...  How do I get those to scroll but leave
> the 2 textview header in place?  Would I create a ScrollView and put
> the new TextViews in that?
>
> I'm probably way off here, but any correcting is fine.
>
> Thanks
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Re: Modifying the UI within Java, not XML

2009-07-11 Thread Mark Murphy

Breezy wrote:
> ListView, okay, that works.  Now how do I make multiple TextViews and
> insert them into the ListView on the fly?

A cursory description of the process can be found here:

http://developer.android.com/guide/topics/ui/binding.html

(in their case they use a Spinner, though the technique is similar)

The Notepad tutorial shows a ListActivity with a ListView:

http://developer.android.com/guide/tutorials/notepad/index.html

as does the Hello, ListView sample:

http://developer.android.com/guide/tutorials/views/hello-listview.html

The API samples in your SDK have a dozen or so using ListView.

If you are trying to get fancier with your ListViews, I have an excerpt
from one of my books that discusses that process:

http://commonsware.com/Android/excerpt.pdf

with sample code available from:

http://commonsware.com/Android

In a nutshell, you create an Adapter object that maps from raw data
(e.g., an array of strings) to Views that go in each row (e.g., a
TextView). How simple or complex that process is depends on how fancy
the rows are. For really simple rows, it's about four lines of code.

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

Android 1.5 Programming 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 android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Re: Modifying the UI within Java, not XML

2009-07-11 Thread Breezy

ListView, okay, that works.  Now how do I make multiple TextViews and
insert them into the ListView on the fly?

Thanks for the fast response BTW.



On Jul 11, 6:02 pm, Mark Murphy  wrote:
> Breezy wrote:
> > Kinda like if you search for
> > an app in the market.  There's no way of telling how many results
> > would be returned so I figured I would have to create each textview on
> > the fly within the .java file.
>
> Use a ListView. I'm 90% certain that is what they do. It automatically
> scrolls, manages an arbitrary number of rows, etc.
>
> --
> Mark Murphy (a Commons 
> Guy)http://commonsware.com|http://twitter.com/commonsguy
>
> Android 1.5 Programming 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 android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Re: Modifying the UI within Java, not XML

2009-07-11 Thread Mark Murphy

Breezy wrote:
> Kinda like if you search for
> an app in the market.  There's no way of telling how many results
> would be returned so I figured I would have to create each textview on
> the fly within the .java file.

Use a ListView. I'm 90% certain that is what they do. It automatically
scrolls, manages an arbitrary number of rows, etc.

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

Android 1.5 Programming 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 android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---