Monday, April 23, 2012

[android-developers] ListView addHeader(View) problem control image enhancement

Seems so simple...create a textview, prior to adding the arrayAdapter,
apply the header as myListVew.addHeader(t); then (or before) set the
text for the TextView (t) with t.setText(aString). (I believe the actual
variable's name was flashCurrentMode).

Here's basically what I did (I originally deleted the code when it
failed...not good, so I'm recreating it in more generic code).

Textview t; // defined globally

Later, while setting up the ListViews

t = new TextView(this);
String s = parameters.getFlashMode(); // Log.i verifies that s != null
t.setText(s);
mbigListView.addHeader(t);
// attach to array adapter here

That works. The first time I make that ListView visible, it
has a header showing the current flash mode, which is exactly
what I wanted it to do. The problem comes when I CHANGE the
flash mode, and, from within the onItemClick for mbigListView,
do (almost) the same as earlier:

First, to set s, I tried both of the following (after setting the new
parameters):

String s = parameters.getFlashMode();
String s = flashModes(idx);

Either way, Log.i confirms, s is "torch" (the new flash mode).
Then, continuing with setting the new header,

t.setText(s); // THIS causes a Null Pointer Exception//Force Close

mbigListView.addHeader(t); // we never get this far


Why would setting the text of the TextView the second time cause a force
close (caused by a null pointer exception, where the string being
assigned was not null)?

I know I'm missing something...but what? It seems amazingly simple,
but something obviously isn't as simple as it appears from the dev guide.

Thanks,
--jim

--
THE SCORE: ME: 2 CANCER: 0
73 DE N5IAL (/4) | DMR: So fsck was originally called
spooky130u@gmail.com | something else.
< Running FreeBSD 7.0 > | Q: What was it called?
ICBM / Hurricane: | DMR: Well, the second letter was different.
30.44406N 86.59909W | -- Dennis M. Ritchie, Usenix, June 1998.

Android Apps Listing at http://www.jstrack.org/barcodes.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+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate