Category: "Android programming"
Using mocking GPS app to test app
In your development option, you pick an app to mock your GPS location. I used this way to pretend I was in Hong Kong to test some apps for my clients in Hong Kong. But I found after that, even I switched off that GPS mocking. I found some funny behaviors. I turned on the navigation in Google map. Yes, at the first, GPS position is right, back to Australia, not in Hong Kong anymore. But my car was driving, the GPS position won't update. After I turned off my phone and turn it back on again. Then that is normal. I think after mocking GPS position, you need to reset the GPS. I know some apps can do.
Keeping the FAB Button at right bottom side
I put every fragment with their own FAB Button. I found that is always placed under the last element of that layout. It won't be pushed further bottom, at the right bottom of the screen. I used to use the LinearLayout and RelativeLayout, they won't work too.
FInally, I found android.support.design.widget.CoordinatorLayout is only way to work, I don't know why yet, I found this solution by trial and error
Code
<android.support.design.widget.CoordinatorLayout | |
android:id="@+id/rootLayout" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent"> | |
<android.support.design.widget.FloatingActionButton android:id="@+id/fab" | |
android:layout_width="wrap_content" android:layout_height="wrap_content" | |
android:layout_gravity="bottom|end" android:layout_margin="@dimen/fab_margin" | |
android:src="@android:drawable/ic_input_add" /> | |
</android.support.design.widget.CoordinatorLayout> |
Android Studio is updated to 1.4
Last night, I upgraded my android studio from 1.2 to 1.4. I have used android studio for more than a year. In old time, that was still in beta. Every upgrades, I needed to fixes the project files. This times, that was hassle-free, it only required to download 2GB files for library and sdk update. That is great. I love it.
Set the Empty view of ListView
I found ListView control in Android is very easy to use, that is very good. Even there is a method to set the empty view, it will display it when the list context is empty.
You put any view in there. I put a LinearView with a Textview. That is easy!
Code
View empty= (View)view.findViewById(android.R.id.empty); | |
mListView.setEmptyView(empty); |
The Event in Fragment should be triggered when the fragment go to sleep
If you wish to do some actions, such as auto save, when the user go to other app, therefore the user put your app in a sleep mode at the background
You must override the onPause() method like below:
Code
@Override | |
public void onPause() { | |
super.onPause(); | |
if (!txtTitle.getText().equals("")) { | |
saveTag();; | |
} | |
} |