Adding an “options menu” to an Android app’s Activity is quite simple. This is an example of what an Android options menu looks like. Look at the icon that looks like 3 dots vertically stacked. My dev environment status as of writing this Android Studio version: v. 2.1 OS: Mac OS X El Capitan v. […]
Android Development
Android app development: click a ListView item programmatically
I’m going to share a code snippet that you may use to programmatically click a ListView item in your Android app. This will not simply highlight the desired ListView item, but also trigger the onItemClick listener. This code is what I placed in a Fragment’s onLoadFinished() method:
1 2 |
int default_position = 2; listView.performItemClick(listView.getChildAt(default_position), default_position, listView.getItemIdAtPosition(default_position)); |
Simply replace the default_position value with the […]
Android app dev: Add ActionBar to Preference Activity
When I converted an activity into PreferenceActivity, I noticed that its ActionBar disappeared. I’ll show you how I brought the ActionBar back to my PreferenceActivity. In this guide I will assume that the name of the file that contains your is SettingsActivity.java, and that the view assigned to your SettingsActivity.java is named . First, create […]
Android app dev: ShareActionProvider in Activity & Fragment
I’ve been taking the Developing Android Apps course on Udacity, and yesterday I encountered a difficulty in solving the Quiz: Share Intent. One of the course’s goal is to build the Sunshine App – an Android app with weather forecast. In that quiz I had to implement ShareActionProvider on my DetailsFragment so that a share […]
Android M runtime permissions utility class
Hello world, I prepared a PermissionsUtil.java class and it’s on GitHub. Check it out: AndroidPermissionsUtil Why use it? It will help by letting you write less code as you add conditions to your Android app that supports Android 6.0 (Marshmallow). The utility class defines helper methods that were used in the following example. Sample usage […]
Android app codes for Google Maps with clustering
I prepared Android app codes with Google Maps and clustering feature. Feel free to use these as basis for your new projects. They are on GitHub: [1] Default Map Markers: catzie/SimpleAndroidMapClustering [2] Custom Map Markers: catzie/Simple-Android-Map-Clustering-with-Custom-Markers I simply took the necessary classes and res files from Android Maps Utility demo, and then placed […]
Android Maps: Get current location coordinates with Google API Client Builder
To get your current location via Google Map in an Android app, this was how we do it:
1 2 3 4 |
@Override public void onMapReady(GoogleMap googleMap) { Location location = googleMap.getMyLocation(); } |
Stop. Don’t use that! The method GoogleMap.getMyLocation() is deprecated. Instead, we need to use FusedLocationApi and the callback onLocationChanged(). Here’s an example code that works for me ( consider copying the contents of onResume() into onStart() […]
Android Studio: add Google Map from empty activity (dev note)
//Update: I prepared a simple Android app that features a Google Map with markers that form clusters together when zoomed out. Check it out: Simple Android Map Clustering on GitHub. This “dev note” of mine will give you a rough idea on how to add a Google Map to your Android up from an empty […]
Android Development: Permission denied when running ./gradlew in Mac
I’m using a Mac at the moment to work on my Android app projects. For some reason I need to run ./gradlew in the terminal, but I was getting this error: -bash: ./gradlew: Permission denied To fix this, what I did was run the following commands:
1 2 |
Mac-mini:projname moi$ chmod +x gradlew Mac-mini:projname moi$ ./gradlew |
After those commands, my Mac downloaded numerous files […]
Android Studio and the 64K methods limit (DEX error)
Hi! I’ll share a few tips with you on how to find out the number of methods that your Android app has. I’m gonna show you a few tools such as APK file methods counter, and an Android plugin that will show you the number of methods each imported class or dependency has. These will […]