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

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.

Related

Any way to see all the methods that don't work at once? Android Studio

I have to estimate the time it takes to update a specific application made for Android 4.4 to Android 10 and I need to see all the methods that are deprecated or not working. Is there any way to see the methods without going file by file? (I'm using Android Studio with Java)
When I build the application I only get one or two types of error at a time, when I correct them I get another one and so on.
Thanks and best regards.
P.S: How long does it take you to update something like that? I'm a junior and I'm a little lost doing this.
Here, go to Analyze -> Inspect code. After inspecting check maturity there you will have depreciated methods. (Don't forget to change minSdk)
After you will do that it give you method with a warning and you can filter it by having API not support warning

ConstraintLayout doesn't match with the screen size

I just started my first Android Studio project and I already come with a problem :)
I search on google for the answer but didn't find my problem.
So I need your help please ^^
I download the last version of Android Studio, create a project with an Empty Activity and I came up with this
As you can see my ConstraintLayout is really small and I just can't work with this.
I didn't touch anything on the project. Just to be sure I create 3 projects that have the same issue and redownload 4 time Android Studio.
On the virtual Devices, it looks correct throw: Screenshot
I put the XML code just in case it can help
xmlcode
Hope I was clear and sorry for my English ;)
EDIT: For some reason, the constraint layout fit correctly on the watch screen, but I don't want to create a watch app x) screenshot_watchview
Ok so I have finally find the problem ! I'm so happy right now :D
The problem was the AppTheme theme that I use, I switch it with the DeviceDefault theme. I don't know why this theme was causing problem but now it work and I can finally work on my first Android App !
If you are using the supportLibrary 28+ then this thing happened to me too.
and when I change the support lib version to the 27, it works.
Maybe this is a possible bug in the support library 28+.
Changing the AppTheme works like a charm if you want to stick with the support library 28+ But if you still don't want to so Try using the support library below 28.

Running apps containing large amount of code

Background
It seems some old Android OSs (and maybe even the newest ones) have a limitation on the amount of code each app can hold.
As I've found, the limitation is on a buffer called "LinearAlloc" .
On 2.2 or 2.3 it's about 5-8 MB , and I think it's 16 or more on others.
The problem
If you have a too large code (and apps can reach this state), you won't be able to install the app at all on older devices, getting the next error (also reported here) :
Installation error: INSTALL_FAILED_DEXOPT
Please check logcat output for more details.
Launch canceled!
What I've found
One solution is to just remove as much code and libraries as possible, but on some huge projects such a thing is very hard to do.
I've found the next links talking about how Facebook solved this, by somehow increasing the limit:
http://www.slashgear.com/how-facebook-fixed-its-gingerbread-dalvik-problem-04272478/
http://arstechnica.com/business/2013/03/how-facebook-dug-deep-within-android-to-fix-its-mobile-app/
https://www.facebook.com/notes/facebook-engineering/under-the-hood-dalvik-patch-for-facebook-for-android/10151345597798920
Also, Google has posted how to solve it by loading code dynamically :
http://android-developers.blogspot.co.il/2011/07/custom-class-loading-in-dalvik.html
The question
How did Facebook do it?
Is it possible to overcome this in other ways too?
Is there any free library that increases/removes the limitation of this buffer?
What is the limitation on newer Android versions, if there is any?
How do other huge apps (and games) handle this issue? Do they put their code into C/C++?
Would loading the dex files dynamically solve this?
The limit is the total number of method references:
https://code.google.com/p/android/issues/detail?id=7147#c6
https://code.google.com/p/android/issues/detail?id=20814#c6
A middle ground between doing nothing and the multi-dex approach described in the FB/Google articles is to use a tool like ProGuard to remove references to unused code at the Java level. See:
http://proguard.sourceforge.net/
http://developer.android.com/tools/help/proguard.html
There is a new solution, made by Google:
https://plus.google.com/+IanLake/posts/JW9x4pcB1rj?utm_source=Android%20Weekly&utm_campaign=59f1f4bf4d-Android_Weekly_125&utm_medium=email&utm_term=0_4eb677ad19-59f1f4bf4d-337848877
http://developer.android.com/reference/android/support/multidex/MultiDexApplication.html
It seems all you have to do is any of the next things:
- extend from "MultiDexApplication" instead of from "Application"
- call MultiDex.install(context) in your application's attachBaseContext
But now I wonder:
Is that really it?
Does it have any issues ? Does it affect performance?
How does it work?
What should be done with ContentProvider, as it's getting called before Application gets initialized?
The post says "gives you MultiDex support on all API 4+ devices (well, until v21, where you get this natively)" . Does it mean that from v21 it will be the default behavior, or just that the class will be built in and you won't need to use the support library's class ?
Will this solution work on Eclipse too?

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.

Button clicks in API level 3?

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.

Categories

Resources