I want to use a Master-Detail-Flow with a GridView on the left (master) side.
According to the documentation, GridView has a method setItemChecked(position, value) that was added in API level 1. Eclipse however states that the method requires API level 11.
Which one is true? If I want to have checked items in my GridView, do I need to implement the logic (with background changes etc) myelf?
From my experience, the official documentation is wrong.
AbsListView.setItemChecked(position, value) only exists from HoneyComb (API 11) onwards. What makes it confusing is that ListView.setItemChecked(position, value) did exist from API 1 while GridView.setItemChecked(position, value) didn't. I think it was just bad API design that was fixed in API 11.
Maybe it's due to a limitation in the documentation generator because the method was moved up the inheritance chain to AbsListView in API 11. The method in AbsListView should be marked as Added in API level 11 while the method in ListView should be marked as Added in API level 1.
I haven't used it but someone has created a GridViewCompat to fix this issue.
https://github.com/paramvir-b/AndroidGridViewCompatLib
I believe the documentation is wrong. Testing on an emulator, the method was not available on API level 8. This applies for all extensions of the AbsListView setItemChecked() method as far as I can tell (ListView etc). I think it's safe to assume it's only available on API level 11+
Related
I recently came across the deprecation of clipRect(Rect,Region.Op), which I would like to use with DIFFERENCE. This was replaced with clipOutRect(Rect) and thus I implemented:
#Suppress("DEPRECATION")
fun clipOutRect(canvas: Canvas, rect: Rect) =
if (SDK_INT >= O) canvas.clipOutRect(rect)
else canvas.clipRect(rect, DIFFERENCE)
Now this looks like it could be a compatibility method in AndroidX, but for some reason I was not able to figure out, where I could find it exactly.
Is there a class already providing a compatibility method for clipOutRect(Rect)?
Short answer is - no. The only thing related to Canvas in AndroidX is this file: https://github.com/aosp-mirror/platform_frameworks_support/blob/androidx-master-dev/core/core-ktx/src/main/java/androidx/core/graphics/Canvas.kt
Long answer.
First of all, Canvas is passed to view by native code, so it will be awkward to have something like onDrawCompat(canvas: CanvasCompat) in ViewCompat class. And I think there is no reason to do that at all.
Also, it's really not that type of deprecation you should worry about.
For example WifiManager.startScan() is noted with
This method was deprecated in API level 28. The ability for apps to
trigger scan requests will be removed in a future release.
That says Change this code now, or it will be broken year later
That not the case with clipRect, it will be kept for backward compatibility with apps that won't be ever updated for years or even tenth of years. Deprecation warning for this is just like Hey, we have new method with better functionality/name, if you target minimum is API 26 you can use that
I have one custom class having initializeScrollBars() in its constructor.
In API 21, the method was removed, so i am not able to build the app on Lollipop 5.0.I have searched and found that, there is no alternative provided by android officially.
(https://developer.android.com/sdk/api_diff/21/changes/android.view.View.html).
I have checked this link: initializeScrollbars is undefined? and noticed that one developer suggest us to remove the method and let it on the View class by defining R.styleable.View_scrollbars attr which is not internal.
I just don't get it.
Google have answered for this issue as:
"The API has been removed because R.styleable is not public or stable. There is no safe way to pass a TypedArray into that method. Don't call the method."(Ref: https://github.com/GDG-Korea/PinterestLikeAdapterView/issues/31)
Can anyone light me a path how to remove the method
initializeScrollbars() from the custom view?
Can i simply remove initializeScrollbars() from constructor ?
What is the best way to initialize scrollbars of a custom view.?
I have issues in my app regarding StrictMode and added the code snippet that basically disables the StrictModeHelper. However, Lint complains about setThreadPolicy() now and proposes to either add
#SuppressLint 'NewApi'
or
#TargetApi(Build.VERSION_CODES.GINGERBREAD)
to the onCreate() event of the view.
Which method is prefered ..or are they basically doing the same?
I have issues in my app regarding StrictMode and added the code snippet that basically disables the StrictModeHelper
Please fix the networking bug.
Which method is prefered ..or are they basically doing the same?
#TargetApi and #SuppressLint have the same core effect: they suppress the Lint error.
The difference is that with #TargetApi, you declare, via the parameter, what API level you have addressed in your code, so that the error can pop up again if you later modify the method to try referencing something newer than the API level cited in #TargetApi.
For example, suppose that, instead of blocking the StrictMode complaints about your networking bug, you were trying to work around the issue of AsyncTask being serialized on newer versions of Android. You have a method like this in your code to opt into the thread pool on newer devices and use the default multithread behavior on older devices:
#TargetApi(11)
static public <T> void executeAsyncTask(AsyncTask<T, ?, ?> task,
T... params) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params);
}
else {
task.execute(params);
}
}
Having #TargetApi(11) means that if Lint detects that I am using something newer than my android:minSdkVersion, but up to API Level 11, Lint will not complain. In this case, that works. If, however, I modified this method to reference something that wasn't added until API Level 14, then the Lint error would appear again, because my #TargetApi(11) annotation says that I only fixed the code to work on API Level 11 and below above, not API Level 14 and below above.
Using #SuppressLint('NewApi'), I would lose the Lint error for any API level, regardless of what my code references and what my code is set up to handle.
Hence, #TargetApi is the preferred annotation, as it allows you to tell the build tools "OK, I fixed this category of problems" in a more fine-grained fashion.
TextView.setAllCaps() started as of API 14. What is its equivalent for older APIs (e.g. 13 and lowers)?
I cannot find such method on lower APIs. Is maybe setTransformationMethod() responsible for this on older APIs? If yes, how should I use it? TextView.setTransformationMethod(new TransformationMethod() {... is a bit confusing.
Try this:
textView.setText(textToBeSet.toUpperCase());
What about oldskool strtoupper()?
Bottom line is that toUpperCase() is the solution. I can't object that. If you prefer doing the setAllCaps() with TransformationMethod, take a look at my answer.
How can i call perspectiveM static method in Matrix class?
As said here:
http://developer.android.com/reference/android/opengl/Matrix.html
Сode completion suggests me frustumM, invertM, length, multiplyMM, multiplyMV, orthoM and others and no perspectiveM.
Details that could be important: last eclipse and java, android 2.3 as target, last sdk updates.
p.s. i know that i can tune matrix manually. it's just really interesting where method is.
The method is api lvl 14. If you scroll down to perspectiveM on the page you linked, you'll see in faint grey writing the api level where the method was included from: