The date picker for the scheduler part of my app has somehow completely disappeared from existence. Did I dream that this was a working widget and never bothered to try it out in real life!? Anyhow, I'm trying to implement a date picker from an options menu click event inside a tabhost and the code is giving me a load of problems. Damn you, ambiguously written android dev tutorial!
The result -- I think trying to implement a date picker in tabhost is impossible. Something about the content view... had to work around the problem by adding a "select a date" button into the activity controlling that particular tab and removing the troublesome item from the options menu.
Monday, December 13, 2010
Friday, December 3, 2010
Saving State on Orientation Change
Problem:
Form loses state on orientation change. This is due to onCreate being called on orientation change. This affects pages with forms half-filled out becoming blank.
Solution:
In Manifest.xml, go to Application tab, select the Activity in question (yes, you have to do this for EVERY activity you want to protect). For Config Changes select “keyboardHidden” and “orientation”. Worked for me.
Repainting a ListView Adapter from a Separate Activity
Basically, I have a page with a search box. You search for something, get the results in the form of a list on a pop-up dialog (which has its own activity). When you select one of the results, the dialog closes, and the item is added to the original page with the search box. You can repeat this, ad nauseum. *NOTE* This method requires an API level of at least 1.6.
PageOne.java
Be sure to declare variables for the strings and adapter before onCreate. Static makes it available to use by other activities in the package:
static List<String> strings; ListView lv; static ListAdapter adapter;
Define these variables inside onCreate:
strings = new ArrayList<String>();
lv = getListView();
adapter = new ArrayAdapter<String>(this, R.layout.list_item, R.id.label, strings);
lv.setAdapter(adapter);
PageTwo.java
In the onClick method, add code to transform selected item to a string value. Then, adds the item to the String Array in PageOne. Last, notifyDataSetChanged on the adapter used in pageone:
@Override
public void onListItemClick(ListView parent, View v, int position, long id) {
selected = ((TextView) v).getText().toString();
PageOne.strings.add(selected);
((ArrayAdapter<String>) PageOne.adapter).notifyDataSetChanged();
this.finish();
}
PageOne.java
Be sure to declare variables for the strings and adapter before onCreate. Static makes it available to use by other activities in the package:
static List<String> strings; ListView lv; static ListAdapter adapter;
Define these variables inside onCreate:
strings = new ArrayList<String>();
lv = getListView();
adapter = new ArrayAdapter<String>(this, R.layout.list_item, R.id.label, strings);
lv.setAdapter(adapter);
PageTwo.java
In the onClick method, add code to transform selected item to a string value. Then, adds the item to the String Array in PageOne. Last, notifyDataSetChanged on the adapter used in pageone:
@Override
public void onListItemClick(ListView parent, View v, int position, long id) {
selected = ((TextView) v).getText().toString();
PageOne.strings.add(selected);
((ArrayAdapter<String>) PageOne.adapter).notifyDataSetChanged();
this.finish();
}
Thursday, December 2, 2010
"Conversion to Dalvik format failed with error 1"
Ugh. Don't you hate errors that aren't in the code, and don't go away no matter how many times you fix project setup or clean.
Heres what I got in the console:
[2010-12-02 10:38:10 - MDatHand]
trouble processing "java/lang/Object.class":
[2010-12-02 10:38:10 - MDatHand]
Attempt to include a core VM class in something other than a core library.
It is likely that you have attempted to include the core library from a desktop
virtual machine into an application, which will most assuredly not work. If
you really intend to build a core library -- which is only appropriate as
part of creating a full virtual machine binary, as opposed to compiling an
application -- then use the "--core-library" option to suppress this error
message. If you go ahead and use "--core-library" but are in fact building
an application, then please be aware that your build will still fail at some
point; you will simply be denied the pleasure of reading this helpful error
message.
[2010-12-02 10:38:10 - MDatHand] 1 error; aborting
[2010-12-02 10:38:10 - MDatHand] Conversion to Dalvik format failed with error 1
Oh yeah... this was certainly a real pleasure... jerk. The only thing I understand in all that garbage is "library" not that that give me any damn clue on how to fix it. How but just a nice error message that says "FIX YOUR LIBRARY SETTINGS"????? Anywho, I digress...
I did some soul searching on the interwebs, and a nice man by the name of Jim had posted a reasonable solution. I'm posting it herein the event the error pops up again again:
I received the following message and found several others who had seen
it but no solution. So I have included how I finally fixed it. (I'm
using Eclipse version 3.4.2 and Android 1.5.)
...
The fix for me was to go to my project's properties, select:
Java Build Path -> Libraries (tab)
Somehow, the android.jar had been added, and when I deleted it, all
was good. Note that the android.jar is included as part of the
Android 1.5 library, so this was a duplication.
How did this happen? I certainly didn't do it. But my app has blown
up a lot in the emulator, so who knows.
Later . . . Jim
THANKS JIM :]
Heres what I got in the console:
[2010-12-02 10:38:10 - MDatHand]
trouble processing "java/lang/Object.class":
[2010-12-02 10:38:10 - MDatHand]
Attempt to include a core VM class in something other than a core library.
It is likely that you have attempted to include the core library from a desktop
virtual machine into an application, which will most assuredly not work. If
you really intend to build a core library -- which is only appropriate as
part of creating a full virtual machine binary, as opposed to compiling an
application -- then use the "--core-library" option to suppress this error
message. If you go ahead and use "--core-library" but are in fact building
an application, then please be aware that your build will still fail at some
point; you will simply be denied the pleasure of reading this helpful error
message.
[2010-12-02 10:38:10 - MDatHand] 1 error; aborting
[2010-12-02 10:38:10 - MDatHand] Conversion to Dalvik format failed with error 1
Oh yeah... this was certainly a real pleasure... jerk. The only thing I understand in all that garbage is "library" not that that give me any damn clue on how to fix it. How but just a nice error message that says "FIX YOUR LIBRARY SETTINGS"????? Anywho, I digress...
I did some soul searching on the interwebs, and a nice man by the name of Jim had posted a reasonable solution. I'm posting it herein the event the error pops up again again:
I received the following message and found several others who had seen
it but no solution. So I have included how I finally fixed it. (I'm
using Eclipse version 3.4.2 and Android 1.5.)
...
The fix for me was to go to my project's properties, select:
Java Build Path -> Libraries (tab)
Somehow, the android.jar had been added, and when I deleted it, all
was good. Note that the android.jar is included as part of the
Android 1.5 library, so this was a duplication.
How did this happen? I certainly didn't do it. But my app has blown
up a lot in the emulator, so who knows.
Later . . . Jim
THANKS JIM :]
Subscribe to:
Posts (Atom)