Android tricks
This post will gather all those little tricks that speed up your Android development, because I found I often get stuck because of poor documentation.
PopupMenu:
supply x and y, otherwise it won’t show up
set a background drawable, or it won’t react to touch events
You need a style with two items for animation to work http://stackoverflow.com/a/7550227/315306
SQLite
Primary key must be defined
INTEGER PRIMARY KEY NOT NULL(WTF? Not null?) And be careful that if you useINTinstead ofINTEGER, you won’t have the autoincrement behaviorPrimary key must be explicitly enabled with
PRAGMA foreign_keys = ON;(doc). Usually this is done insideonOpen(SQLiteDatabase), after checking that the database is writeableUse the class DatabaseUtils
ViewAnimator
- Batch removing children is tricky. First, you must
post()to the animator’s Handler. Then you need to set in and out animations tonull. Finally, removeViews(int start, int count) doesn’t work well, so you have to remove one child at a time, either withremoveView(View view)orremoveChildAt(int index)
EditText
getText()returns aCharSequence. It never returnsnull, so you must check its length to tell if it’s empty.