[android-developers] Re: How to initialize visibly gone UI elements?

2011-04-21 Thread Keith Wiley
I agree that yours seems to work.  I'm trying to figure out the
difference between our code now.  Thanks.

On Apr 21, 6:42 am, Mark Murphy mmur...@commonsware.com wrote:
 I cannot reproduce your problem.

 For example, try:

 http://misc.commonsware.com.s3.amazonaws.com/SpinnerGone.zip

 This is the Selection/Spinner example from one of my books, with two changes:

 1. It sets android:visibility=gone on the Spinner in the layout

 2. It logs the selected item from the Spinner in onDestroy()

 It works properly, showing the automatically-selected first word out
 of the ArrayAdapter.









 On Thu, Apr 21, 2011 at 9:21 AM, Keith Wiley kbwi...@gmail.com wrote:
  I have a large layout and I hide whole sections of it at a time by
  wrapping numerous related UI elements in a sublayout and toggling that
  sublayout's visibility between visible and gone via a button
  (which is obvious not contained within the sublayout itself).  I want
  to start with all these section sublayouts in the gone state
  (either in the xml itself, or by setting those layouts to gone in
  onCreate(), I've tried it both ways, same erroneous result occurs).
  That is, I want all sections to be initially minimized and the overall
  layout as minimal as possible.

  At onCreate() time I initialize all my UI elements.  Later, when the
  user closes the layout I want to read all the settings of all the
  elements.  However, those that were gone during initialization
  (which is to say, all of them since I start with everything gone)
  were never initialized (for example, a spinner's selected view is null
  despite having been assign in onCreate()).  I interpret this as
  indicating that UI elements are not really assigned when you assign
  them, but rather, during layout time, so if the element is never
  visible, the command to assign its value (a spinner's selection) never
  follows through.

  So, it seems like commands to assign UI element values only occur
  after the elements are laid out, meaning after they become visible.
  Will commands to initialize an element never take effect if the
  element is never made visible?  If so, how do I achieve my intended
  goal of a bunch of hidden settings, some of which may not even be
  unhidden at all before the user decides to exit the settings?

  --
  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

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

 Android 3.0 Programming Books:http://commonsware.com/books

-- 
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: How to initialize visibly gone UI elements?

2011-04-21 Thread Andy
Maybe you attach you sub-Layouts to parent Layout which refreshes all
child elements when the layout changes.

You can hide Elements from a parent layout programmatically - which
works fine for my usecase.

onCreate : Creates all Elements that may or may not be visible.(In my
case is't a Dialog)

so before i call show() on the dialog element, i clean the element
Container where all my visible elements should be in.


1. layoutContainer.removeAllViews();

2. than i set my Values to Subviews and add their references to a
Array (Those Subviews where all already initialized in onCreate)

3. after i set all my texts and remembering what i wanted to show, i
iterate over the Array (mRenderCache)
for(View v: mRenderCache){
layoutContainer.addView(v);
}

4. Nothing is visible atm, but now i show the dialog by calling show()








On 21 Apr., 16:13, Keith Wiley kbwi...@gmail.com wrote:
 I agree that yours seems to work.  I'm trying to figure out the
 difference between our code now.  Thanks.

 On Apr 21, 6:42 am, Mark Murphy mmur...@commonsware.com wrote:

  I cannot reproduce your problem.

  For example, try:

 http://misc.commonsware.com.s3.amazonaws.com/SpinnerGone.zip

  This is the Selection/Spinner example from one of my books, with two 
  changes:

  1. It sets android:visibility=gone on the Spinner in the layout

  2. It logs the selected item from the Spinner in onDestroy()

  It works properly, showing the automatically-selected first word out
  of the ArrayAdapter.

  On Thu, Apr 21, 2011 at 9:21 AM, Keith Wiley kbwi...@gmail.com wrote:
   I have a large layout and I hide whole sections of it at a time by
   wrapping numerous related UI elements in a sublayout and toggling that
   sublayout's visibility between visible and gone via a button
   (which is obvious not contained within the sublayout itself).  I want
   to start with all these section sublayouts in the gone state
   (either in the xml itself, or by setting those layouts to gone in
   onCreate(), I've tried it both ways, same erroneous result occurs).
   That is, I want all sections to be initially minimized and the overall
   layout as minimal as possible.

   At onCreate() time I initialize all my UI elements.  Later, when the
   user closes the layout I want to read all the settings of all the
   elements.  However, those that were gone during initialization
   (which is to say, all of them since I start with everything gone)
   were never initialized (for example, a spinner's selected view is null
   despite having been assign in onCreate()).  I interpret this as
   indicating that UI elements are not really assigned when you assign
   them, but rather, during layout time, so if the element is never
   visible, the command to assign its value (a spinner's selection) never
   follows through.

   So, it seems like commands to assign UI element values only occur
   after the elements are laid out, meaning after they become visible.
   Will commands to initialize an element never take effect if the
   element is never made visible?  If so, how do I achieve my intended
   goal of a bunch of hidden settings, some of which may not even be
   unhidden at all before the user decides to exit the settings?

   --
   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

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

  Android 3.0 Programming Books:http://commonsware.com/books

-- 
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: How to initialize visibly gone UI elements?

2011-04-21 Thread Keith Wiley
I have determined the discrepancy.  Your code calls getSelectedItem()
on the spinner.  Mine calls getSelectedTextView().  In your case, you
get a non-null response regardless of the visible status.  In mine, I
get a null if it is initially gone, but I get a TextView if it is
initially visible.  Furthermore, if I toggle the spinner's visibility
from gone to visible, I get a non-null response, AND if I toggle
twice, thus hiding the spinner again, I still get a nonnull response.

Here's my modification of your code that demonstrates this point:
http://www.keithwiley.com/Downloads/Spinner2.zip

If you exit immediately, it says the selected text view is null.  If
you toggle the button once to show the spinner and exit, it says the
text view is not null.  BUT, if you toggle it twice, showing and
hiding the text view, then exit, it STILL says the text view is not
null, so it needs to draw the spinner once and then it's good to go
even if the spinner is subsequently hidden.

-- 
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


Re: [android-developers] Re: How to initialize visibly gone UI elements?

2011-04-21 Thread Mark Murphy
On Thu, Apr 21, 2011 at 11:17 AM, Keith Wiley kbwi...@gmail.com wrote:
 I have determined the discrepancy.  Your code calls getSelectedItem()
 on the spinner.  Mine calls getSelectedTextView().  In your case, you
 get a non-null response regardless of the visible status.  In mine, I
 get a null if it is initially gone, but I get a TextView if it is
 initially visible.  Furthermore, if I toggle the spinner's visibility
 from gone to visible, I get a non-null response, AND if I toggle
 twice, thus hiding the spinner again, I still get a nonnull response.

Right. If an AdapterView is hidden, it is not querying the Adapter for
any rows/cells/whatever, and so you'll get null for getSelectedView().
This is a perfectly reasonable optimization, IMHO.

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

Android 3.0 Programming Books: http://commonsware.com/books

-- 
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: How to initialize visibly gone UI elements?

2011-04-21 Thread Keith Wiley
I agree, and I can adapt my code to use the selected item instead of
the selected view...but it is worth noting that the consequence of
this is that seemingly identical layouts can yield very different
behavior.  In this case, two layouts containing invisible items can
return either a valid view or a null, which is both dangerous and
somewhat arbitrary...not random of course, but slightly arbitrary.
I'm just pointing that out, I'm not arguing against the optimization
necessarily.

On Apr 21, 8:24 am, Mark Murphy mmur...@commonsware.com wrote:
 On Thu, Apr 21, 2011 at 11:17 AM, Keith Wiley kbwi...@gmail.com wrote:
  I have determined the discrepancy.  Your code calls getSelectedItem()
  on the spinner.  Mine calls getSelectedTextView().  In your case, you
  get a non-null response regardless of the visible status.  In mine, I
  get a null if it is initially gone, but I get a TextView if it is
  initially visible.  Furthermore, if I toggle the spinner's visibility
  from gone to visible, I get a non-null response, AND if I toggle
  twice, thus hiding the spinner again, I still get a nonnull response.

 Right. If an AdapterView is hidden, it is not querying the Adapter for
 any rows/cells/whatever, and so you'll get null for getSelectedView().
 This is a perfectly reasonable optimization, IMHO.

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

 Android 3.0 Programming Books:http://commonsware.com/books

-- 
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


Re: [android-developers] Re: How to initialize visibly gone UI elements?

2011-04-21 Thread Kostya Vasilyev


A way to look at this which just occurred to me is:

getSelectedItem() has to do with the data backing up the spinner. This 
works even if the spinner stays hidden / gone the whole time, as it 
should, since the data backing up the spinner always exists, regardless 
of UI state.


getSelectedTextView() has to do with the data's presentation. If there 
spinner stayed hidden, there was never any presentation, and that's the 
value you're getting.


Makes sense?

-- Kostya

21.04.2011 20:51, Keith Wiley пишет:

I agree, and I can adapt my code to use the selected item instead of
the selected view...but it is worth noting that the consequence of
this is that seemingly identical layouts can yield very different
behavior.  In this case, two layouts containing invisible items can
return either a valid view or a null, which is both dangerous and
somewhat arbitrary...not random of course, but slightly arbitrary.
I'm just pointing that out, I'm not arguing against the optimization
necessarily.



--
Kostya Vasilyev -- http://kmansoft.wordpress.com

--
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


Re: [android-developers] Re: How to initialize visibly gone UI elements?

2011-04-21 Thread Streets Of Boston
Exactly,

You initialize all your *data *(not your views)* *in the appropriate state. 
Then when the views become visible/available, they get the data and show it 
correctly. 
In other words, the view should be getting the data when they become 
available. Don't 'push' the data to views (that may not yet exists).

-- 
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