Button clicks in API level 3? - android

I've written a relatively simple app, and I've been testing it out on the various different API levels created through the SDK and AVD manager in Eclipse. It works great in all API levels except for level 3. I have a few spinners on the front page which work just fine, but my four buttons don't seem to be working. I've tried adding a breakpoint in one of the 'onClick' methods that I specified in my xml layout file, but the breakpoint never seems to get reached. I'm kind of at a loss here. Does anyone have any idea what could be going on here?

Level 3 does not support the onClick attribute in XML. Unfortunately, you'll have to wire up OnClickListeners in code.
... or drop support for 1.5. It's a small and shrinking part of the market.

Related

Android gui components from 4.x

I have an app for Android where in one screen, we have ToggleButton for 2.x and Switches for 4.x. I was able to create the layout folders for versions layout-v14 etc. and the layout xml's work fine.
My concern is from the coding standpoint, I want to be able to get the component (switch or togglebutton) from code and have it work from API 10 and later. However, the older API's do not have android.widget.switch. Is there any other work around? Otherwise I'll have to show a ToggleButton to all users :(
I treid to read the below for this:
http://www.edumobile.org/android/android-tutorial/switches-example-in-android/
http://developer.android.com/guide/topics/ui/controls/togglebutton.html
I figured it out. They both inherit from CompoundButton. So it's ok to import android.widget.CompoundButton. No need to import ToggleButton or Switch. Case closed.

Layout according to android version

i am trying to make a alarm clock, the GlowPadView in the newer android versions it quite good looking and i was planning to use that in my application, but at the same time i also want to support 2.3.3(Gingerbread) which still has a major chunk of phones. So i was wondering if there is a way that i can check the android version the phone is running and show the layout according to that. If the phone is running API 11 + the layout shows GlowPadView otherwise it shows basic swipe views from the Gingerbread stock alarm application.
To check the android version Build.VERSION_CODES can be used
android.os.Build.VERSION.SDK_INT;
So i was wondering if there is a way that i can check the android version the phone is running and show the layout according to that.
Create separate directories, such as res/layout/ and res/layout-v11/. Have the same-named layout resource in each (e.g., foo.xml), and put the GlowPadView in the foo.xml that you place in res/layout-v11/.
As you stated, you could just create two completely separate layouts, and then have an if (android.os.Build.VERSION.SDK_INT > 11), setContentView() to one layout and if (android.os.Build.VERSION.SDK_INT<=11) setContentView() to a different layout.

tools for creating and checking android layouts

I spend an unpleasant time looking for erros in my android layout, fields not showing up being the predominant one. As I see other people here also struggling a lot with android layouts I thought to throw this question in even so not completely according to the SO question guidelines.
What tools are out there to help with the creation of android layouts.
there is only one i know. its called http://www.droiddraw.org/
over the time i figured though that the best is still to create your own by code.
If you're using a newer SDK within Eclipse (eg android 4.0 or 4.1) it should help you with the layout (with much more functional drag and drop and alignment/spacing). However, you may still want to manually verify it to make sure it's exactly what you want, since you'll be changing other parameters too.

How can I set a GridView's choice mode to multiple?

I have this line in my code:
myGridView.setChoiceMode(GridView.CHOICE_MODE_MULTIPLE);
It works perfectly fine in ICS, but crashes with 2.2 and 2.3.x with the following error:
java.lang.NoSuchMethodError: android.widget.GridView.setChoiceMode
However a look at the docs tells me that the method is supported from API 1, though it's inherited from AbsListView. I also found this issue that reports the problem with no apparent solution
Does anyone now a workaround to this, or have an idea how to set the choice mode to multiple for all versions?
Thanks
There is no solution to this problem if you intend your code to run on API 10 or earlier, the implementation simply isn't there on those older versions of Android.
If you really want a GridView to have a choice mode you will need write the code yourself. The best place to put the code is in your adapter implementation.

Setting Min SDK Version causes app to function improperly: running out of memory

I was getting ready to publish an app, but when I set the min SDK version to anything higher than 3, parts of my app stop working. Specifically I have buttons that launch a new activity, each with different parameters, but only one of them launches the activity if the Min SDK is set (to something other than 1). What am I doing wrong here? I don't think I'm missing any permissions, as the app is relatively simple.
Edit: I was looking at LogCat, and I realized that there seems to be an out of memory issue. Each of the buttons that launches the new activity tells it to load a certain set of images to be displayed, the one button that still functions loads less images. Is there any way to make the app function again without making the images lower quality? Also, why does changing the min SDK version affect this?
The first thing, always, to do is to look at what is being printed in logcat. Very likely there will be error messages there telling you what is going on.
This is a rough documentation on how the various min (actually target) SDK levels modify how the platform behaves for your app: http://developer.android.com/reference/android/os/Build.VERSION_CODES.html
Unfortunately there are probably a few things missing from it, but most of the major differences of interest are there.

Categories

Resources