7. Cara Pakai
ActionBarSherlock
Import Project di Eclipse dan tambahkan sebagai library untuk aplikasi
Gunakan extend milik library
◦ Activity SherlockActivity
◦ Fragment SherlockFragment
◦ FragmentActivity SherlockFragmentActivity
◦ ListAcitivity SherlockListAcitivity
Untuk mengakses Action Bar, gunakan getSupportActionBar()
Pastikan gunakan class milik ActionBarSherlock
◦ com.actionbarsherlock.app.ActionBar
◦ com.actionbarsherlock.view.Menu
◦ com.actionbarsherlock.view.MenuItem
◦ com.actionbarsherlock.view.MenuInflater
TIPS & THIRD PARTY LIBRARY FOR ANDROID 7
11. Membuat Aksi Buka / Tutup
DrawerLayout mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) {
/** Called when a drawer has settled in a completely closed state. */
public void onDrawerClosed(View view) {
getActionBar().setTitle(mTitle);
invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
}
/** Called when a drawer has settled in a completely open state. */
public void onDrawerOpened(View drawerView) {
getActionBar().setTitle(mDrawerTitle);
invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
}
};
// Set the drawer toggle as the DrawerListener
mDrawerLayout.setDrawerListener(mDrawerToggle);
TIPS & THIRD PARTY LIBRARY FOR ANDROID 11
12. Buka / Tutup dengan icon
up
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerToggle = new ActionBarDrawerToggle(
this, /* host Activity */
mDrawerLayout, /* DrawerLayout object */
R.drawable.ic_drawer, /* nav drawer icon to replace 'Up' caret */
R.string.drawer_open, /* "open drawer" description */
R.string.drawer_close /* "close drawer" description */
) {
/** Called when a drawer has settled in a completely closed state. */
public void onDrawerClosed(View view) {
getActionBar().setTitle(mTitle);
}
/** Called when a drawer has settled in a completely open state. */
public void onDrawerOpened(View drawerView) {
getActionBar().setTitle(mDrawerTitle);
}
};
// Set the drawer toggle as the DrawerListener
mDrawerLayout.setDrawerListener(mDrawerToggle);
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
TIPS & THIRD PARTY LIBRARY FOR ANDROID 12
17. Basic Parsing
JSONObject jObj = new JSONObject(strFromUrl);
int id = jObj.getInt("id");
String name = jObj.getString("name");
String address = jObj.getString("address");
String contact = jObj.getString("contact");
//.... dan seterusnya
TIPS & THIRD PARTY LIBRARY FOR ANDROID 17
18. Gson
Unduh library Gson
◦ https://code.google.com/p/google-gson/
Ekstrak hasil unduh dan letakkan library jar ke folder libs di project
Buat kelas model yang mempresentasikan json yang akan diparsing
TIPS & THIRD PARTY LIBRARY FOR ANDROID 18
19. Contoh kelas model
public class RestaurantDao {
String id;
String name;
String address;
String contact;
String links;
String about;
String lat;
String lng;
String currency;
String minprice;
String maxprice;
//.... dan seterusnya
}
TIPS & THIRD PARTY LIBRARY FOR ANDROID 19
20. Parsing menggunakan
Gson
Gson gson = new Gson();
RestaurantDao restaurant = gson.fromJson(strFromUrl,
RestaurantDao.class);
TIPS & THIRD PARTY LIBRARY FOR ANDROID 20