get id of an item in spinner
Make a separate integer-array in XML for the ids: Get the int array in code: Using the position get the correct id from the array in onItemSelected :
Technical answers from my Stack Overflow history, with source links and licenses.
Showing 30 of 231 answers tagged android
Exported May 9, 2026
Make a separate integer-array in XML for the ids: Get the int array in code: Using the position get the correct id from the array in onItemSelected :
Saving all the images in R.drawable is not the best idea. It would be better to save specific images instead of all of them. However, here is how you could save all the images as specified in R.drawable :
You can use a case statement to get the density. This worked for me: Updated code using -le (less than or equal to): Output on my device:
If a ZipException or IOException is being thrown when initializing ZipFile then you should test the integrity of the ZIP. You may also want to make sure you have read/write access. If you are unzipping this file on...
From looking at your code and logs I think your problem is calling onBackPressed in your fragment. Your AlarmFragment.onPause should not be calling getActivity().onBackPressed() . This is most likely what is causing...
You can accomplish this by using a custom theme and setting the following: Or, you can use reflection:
The attachment is not readable by other apps because you are saving it to getFilesDir() . Simply change getFilesDir() to Environment.getExternalStorageDir() and other apps will be able to handle the saved image. This...
Every Activity needs to extend ActionBarActivity. AppCompat doesn't use the native Toolbar or ActionBar, even on Lollipop. For more info see:...
On my device (HTC One M8) android.os.SystemClock is in /system/framework/framework3.jar. I believe framework is separated into multiple jars because of the 65k method limit on classes.dex. android.os.SystemClock may be...
They are different and you should be using sp and not px. Please see this stackoverflow post sp Scale-independent Pixels - this is like the dp unit, but it is also scaled by the user's font size preference. It is...
You can use an open source library to run the command as root. Check out the following libraries: https://github.com/Stericson/RootTools https://github.com/SpazeDog/rootfw https://github.com/Chainfire/libsuperuser...
Here is my current solution. Not ideal, but it should work.
You can build valid HTML for Android TextView using the HtmlDsl library on Github: https://github.com/jaredrummler/HtmlDsl . The library provides syntactic sugar to make the code more understandable and less error-prone...
You can use toybox find : Toybox is included with Android 6.0 (Marshmallow) and all later Android versions.
I would suggest using an architecture where an event bus might not be required. An event bus is still useful and I think you can find what you are looking for in their getting started guide . Some example code:
You need to use DocumentFile.createDirectory(displayName) to create a directory on a removable SD card. See https://stackoverflow.com/a/35175460/1048340
This works with all the examples from your logcat messages: https://regex101.com/r/P7lICp/1 Personally, I would rethink what you are doing.
Two problems I see: 1: You are calling startActivityForResult twice. You can pass extras using intent.putExtra(...) . 2: You don't have a break in your switch statement:
I would use TabBarView . Then, in the Fragment you want a MenuItem to show (like the last tab in Periscope), add setHasOptionsMenu(true) and have the MenuItem 's visibility be app:showAsAction="always" . Wally also uses...
You need to change your Uri . R.drawable.img is a resource id. Example: Change "your.package.here" with the package-name of your application. EDIT I don't have experience with the FacebookSdk. However, a quick Google...
Here are some suggestions: Use a Handler and a Runnable instead of TimerTask . I'm assuming you want to wait n milliseconds before calling textHighLighter(Editable s) after afterTextChanged(final Editable s) is invoked....
You can use DialogFragment and set the animation in onCreateDialog(Dialog) or onStart() . Example from here :
Possible duplicate: Android multidex support library using eclipse It looks like ADT's ant-tasks project is no longer maintained (it resides under 'legacy' folder). So if you can't migrate to Gradle, you can edit the...
Your Activity ( Moovo ) inherits the application theme specified in your AndroidManifest . Your theme is a parent of Theme.AppCompat.Light.DarkActionBar . This theme removes the native android.app.ActionBar which is why...
Are you sure the file exists and you have read access? It is odd that you are creating the parent directory before reading. Check your logcat for the stacktrace. Also, make sure you declared the...
As @CommonsWare pointed out, what you are doing should be OK. It is impossible to guarantee disabled auto-capitalization across all devices. If the user is using a third-party keyboard, like SwiftKey, it may override...
You can use Html.fromHtml(String source) :
Your problem is that in the context of a shell, the path returned from Environment.getExternalStorageDirectory() will throw an error that the file or directory does not exist. You need to change all file paths which you...
You can use reflection. Put the following code in a class and then invoke Foo.isInOverflow(yourMenuItem); Note: you need to add the following line to your proguard configuration file so reflection works in production...
Here is a similar answer to Matthew Willis but with added reflection. Why? because science.