SlideShare a Scribd company logo
Navigation Drawer
by Eakapong Kattiya
http://developer.android.com/training/implementing-navigation/nav-drawer.html
Monday, July 15, 13
by Eakapong Kattiya
Navigation Drawer :Add ActionbarSherlock Library
Source : MyNavigationDrawer.zip
Monday, July 15, 13
by Eakapong Kattiya
Navigation Drawer :Add ActionbarSherlock Library
Monday, July 15, 13
by Eakapong Kattiya
(1)Theme.Sherlock : styles.xml
<resources>
<style name="AppBaseTheme" parent="Theme.Sherlock.Light">
</style>
<style name="AppTheme" parent="AppBaseTheme">
</style>
</resources>
Change AppBaseTheme in styles.xml
Monday, July 15, 13
by Eakapong Kattiya
(2)Theme.Sherlock :AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
//..
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.mydrawerlayout.MainActivity"
android:label="@string/app_name"
android:theme="@style/Theme.Sherlock" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Monday, July 15, 13
by Eakapong Kattiya
Navigation Drawer : activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
//..
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- The main content view -->
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FF00FF" />
<!-- The navigation drawer -->
<ListView
android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#FFFFFF"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp" />
</android.support.v4.widget.DrawerLayout>
</RelativeLayout>
Monday, July 15, 13
by Eakapong Kattiya
Navigation Drawer : main.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:showAsAction="never"
android:title="@string/action_settings"/>
<item
android:id="@+id/action_websearch"
android:icon="@drawable/action_search"
android:showAsAction="ifRoom|withText"
android:title="Search"/>
</menu>
Monday, July 15, 13
import com.actionbarsherlock.app.SherlockFragmentActivity; //import android.app.Activity;
public class MainActivity extends SherlockFragmentActivity implements OnItemClickListener{
	 List<Integer> images = new ArrayList<Integer>();
	 List<String> items = new ArrayList<String>();
	 private ListView mDrawerList;
	 private DrawerLayout mDrawerLayout;
	 @Override
	 protected void onCreate(Bundle savedInstanceState) {
	 	 super.onCreate(savedInstanceState);
	 	 setContentView(R.layout.activity_main);
	 	 images.add(android.R.drawable.ic_menu_gallery);
	 	 images.add(android.R.drawable.ic_menu_camera);
	 	 items.add("Earth");
	 	 items.add("Jupiter");
	 	 mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
	 	 mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); // Set Shadow
	 	 mDrawerList = (ListView) findViewById(R.id.left_drawer);
	 	 ListAdapter adapter = new CustomArrayAdapter(this, items, images);
	 	 // Set the adapter for the list view
	 	 mDrawerList.setAdapter(adapter);
	 	 mDrawerList.setOnItemClickListener(this);
if (savedInstanceState == null) {
selectItem(0);
}
	 }
}
by Eakapong Kattiya
Navigation Drawer : MainActivity.java
Monday, July 15, 13
import com.actionbarsherlock.view.Menu; //import android.view.Menu;
public class MainActivity extends SherlockFragmentActivity
implements OnItemClickListener{
//..
@Override
	 public boolean onCreateOptionsMenu(Menu menu) {
	 	 //getMenuInflater().inflate(R.menu.main, menu);
	 	 getSupportMenuInflater().inflate(R.menu.main, menu);
	 	 return true;
	 }
}
by Eakapong Kattiya
Navigation Drawer : MainActivity.java
Monday, July 15, 13
import com.actionbarsherlock.view.Menu; //import android.view.Menu;
public class MainActivity extends SherlockFragmentActivity
implements OnItemClickListener{
//..
	 @Override
	 public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
	 	 selectItem(arg2);
	 }
	 private void selectItem(int arg0) {
	 	 // update the main content by replacing fragments
	 	 PlanetFragment fragment = new PlanetFragment();
	 	 fragment.setPlanet(items.get(arg0));
	 	
	 	 FragmentManager fragmentManager = getSupportFragmentManager();
	 	 fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
	 	 // update selected item and title, then close the drawer
	 	 mDrawerList.setItemChecked(position, true);
	 	 mDrawerLayout.closeDrawer(mDrawerList);
	 }
}
by Eakapong Kattiya
Navigation Drawer : MainActivity.java
Monday, July 15, 13
import com.actionbarsherlock.view.Menu; //import android.view.Menu;
public class MainActivity extends SherlockFragmentActivity
implements OnItemClickListener{
//..
	 @Override
	 public boolean onOptionsItemSelected(final MenuItem item) {
	 	 // Handle action buttons
	 	 switch (item.getItemId()) {
	 	 case R.id.action_websearch:
	 	 	 // create intent to perform web search for this planet
	 	 	 Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
	 	 	 intent.putExtra(SearchManager.QUERY, getSupportActionBar().getTitle());
	 	 	 startActivity(intent);
	 	 	 return true;
	 	 default:
	 	 	 return super.onOptionsItemSelected(item);
	 	 }
	 }
}
by Eakapong Kattiya
Navigation Drawer : MainActivity.java
Monday, July 15, 13
public class CustomArrayAdapter extends ArrayAdapter<String> {
	 private List<Integer> images;
	 private List<String> items;
	 private Context context;
	 public CustomArrayAdapter(Context context, List<String> items, List<Integer> images) {
	 	 super(context, R.layout.drawer_list_item, items);
	 	 this.context = context;
	 	 this.images = images;
	 	 this.items = items ;
	 }
	 @Override
	 public View getView(int arg0, View convertView, ViewGroup parent) {
	 	 /* create a new view of my layout and inflate it in the row */
	 	 LayoutInflater inflator = (LayoutInflater) context
	 	 	 	 .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	 	 View view = inflator.inflate(R.layout.drawer_list_item, null);
	 	
	 	 TextView textView = (TextView) view.findViewById(R.id.cityName);
	 	 textView.setText(items.get(arg0));
	 	
	 	 ImageView imageCity = (ImageView) view.findViewById(R.id.imageCity);
	 	 String packageName = context.getPackageName();
	 	 String imageName = items.get(position).toLowerCase();
	 	 int resId = context.getResources().getIdentifier(imageName,"drawable", packageName);
	 	 imageCity.setImageResource(resId);
	 	 return view;
	 }
}
by Eakapong Kattiya
Navigation Drawer : CustomArrayAdapter.java
Monday, July 15, 13
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="80dip"
android:background="#222222" >
<ImageView
android:id="@+id/imageCity"
android:layout_width="50dp"
android:layout_height="50dp" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_toRightOf="@id/imageCity"
android:orientation="vertical"
android:paddingLeft="10dp" >
<TextView
android:id="@+id/cityName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"
android:textSize="18dp" />
<TextView
android:id="@+id/cityLink"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:autoLink="web"
android:textColor="#FFFFFF"
android:textSize="14dp" />
</LinearLayout>
</RelativeLayout>
by Eakapong Kattiya
Navigation Drawer : drawer_list_item.xml
Monday, July 15, 13
by Eakapong Kattiya
List vs ArrayList vs LinkedList
List is interface , not a concrete class.
List cannot be instantiated.
List<String> items = new List<String>() ;
ArrayList is an implementation of List.
List<String> items = new ArrayList<String>();
items.add("Earth");
items.add("Jupiter");
LinkedList is an implementation of List.
List<String> items = new LinkedList<String>();
items.add("Earth");
items.add("Jupiter");
Monday, July 15, 13
by Eakapong Kattiya
ArrayList vs LinkedList
- ส่วนใหญ่แล้วใช้ ArrayList
- ใช้ LinkedList เมื่อข้อมูลใหญ่มากเช่น เกิน 1 ล้านแถวจะทํางานเร็วกว่า
(Big-Oh น้อยกว่าเมื่อมีการเพิ่มข้อมูล)
http://leepoint.net/notes-java/algorithms/big-oh/bigoh.html
Algorithm
array
ArrayList
LinkedList
access front O(1) O(1)
access back O(1) O(1)
access middle O(1) O(N)
insert at front O(N) O(1)
insert at back O(1) O(1)
insert in middle O(N) O(1)
Monday, July 15, 13
by Eakapong Kattiya
Sort ArrayList
List<String> items = new ArrayList<String>();
items.add("Earth");
items.add("Jupiter");
Collections.sort(items); //Ascending Sort
Comparator<String> comparator = Collections.reverseOrder();
Collections.sort(items,comparator); //Descending Sort
Monday, July 15, 13
-Fragment is a chunk of user interface with its own life cycle.
-Fragment must exist within an Activity.
-Interaction with fragments is done through FragmentManager.
-Fragment API was introduced in API 11
-Use SherlockFragmentActivity , SherlockFragment
instead of native Fragment API
by Eakapong Kattiya
Fragment (>API 11)
Monday, July 15, 13
by Eakapong Kattiya
Fragment (>API 11)
Monday, July 15, 13
by Eakapong Kattiya
Navigation Drawer : fragment_planet.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:gravity="center"
android:padding="32dp" />
</RelativeLayout>
Monday, July 15, 13
public class PlanetFragment extends SherlockFragment {
	 private String planet ;
	 public PlanetFragment() {
	
	 }
	 public String getPlanet() {
	 	 return planet;
	 }
	 public void setPlanet(String planet) {
	 	 this.planet = planet;
	 }
	 @Override
	 public View onCreateView(LayoutInflater inflater, ViewGroup container,
	 	 	 Bundle savedInstanceState) {
	 	 View view = inflater.inflate(R.layout.fragment_planet, container, false);
	 	 String packageName = getActivity().getPackageName();
	 	 String imageName = planet.toLowerCase();
	 	 int imageId = getResources().getIdentifier(imageName,"drawable", packageName);
	 	 ImageView imageView = (ImageView)view.findViewById(R.id.image);
	 	 imageView.setImageResource(imageId);
	 	 getActivity().setTitle(planet);
	 	 return view;
	 }
}
by Eakapong Kattiya
Navigation Drawer : PlanetFragment.java
Monday, July 15, 13
ImageView imageCity = (ImageView) view.findViewById(R.id.imageCity);
Drawable image = context.getResources().getDrawable(android.R.drawable.ic_dialog_email);
imageCity.setImageDrawable(image);
by Eakapong Kattiya
ImageView
List<Integer> images = new ArrayList<Integer>();
images.add(android.R.drawable.ic_menu_gallery);
images.add(android.R.drawable.ic_menu_camera);
ImageView imageCity = (ImageView) view.findViewById(R.id.imageCity);
Drawable image = context.getResources().getDrawable(images.get(0));
imageCity.setImageDrawable(image);
ImageView imageCity = (ImageView) view.findViewById(R.id.imageCity);
String packageName = context.getPackageName();
String imageName = items.get(position).toLowerCase();
int resId = context.getResources().getIdentifier(imageName,"drawable", packageName);
imageCity.setImageResource(resId);
Fixed Resource id
Dynamic Resource id
Choose image name
Monday, July 15, 13
by Eakapong Kattiya
Nine-patch Image
Monday, July 15, 13
by Eakapong Kattiya
Nine-patch Image
Monday, July 15, 13
by Eakapong Kattiya
Nine-patch Image
res/drawable/drawer_shadow.9.png
Monday, July 15, 13
by Eakapong Kattiya
Navigation Drawer with ActionBarDrawerToggle
Source : MyNavigationDrawerToggle.zip
Monday, July 15, 13
Ad

Recommended

Android basic 2 UI Design
Android basic 2 UI Design
Eakapong Kattiya
 
Android basic 3 Dialogs
Android basic 3 Dialogs
Eakapong Kattiya
 
Android Sliding Menu dengan Navigation Drawer
Android Sliding Menu dengan Navigation Drawer
Agus Haryanto
 
Android dev toolbox
Android dev toolbox
Shem Magnezi
 
Android 3
Android 3
Robert Cooper
 
Android Best Practices
Android Best Practices
Yekmer Simsek
 
Action bar
Action bar
Mu Chun Wang
 
Android App Development - 05 Action bar
Android App Development - 05 Action bar
Diego Grancini
 
Material Design and Backwards Compatibility
Material Design and Backwards Compatibility
Angelo Rüggeberg
 
Implementing cast in android
Implementing cast in android
Angelo Rüggeberg
 
Introduction toandroid
Introduction toandroid
Google Developer Group Bucharest
 
Eddystone beacons demo
Eddystone beacons demo
Angelo Rüggeberg
 
droidparts
droidparts
Droidcon Berlin
 
Advancing the UI — Part 1: Look, Motion, and Gestures
Advancing the UI — Part 1: Look, Motion, and Gestures
Samsung Developers
 
Android - Working with Fragments
Android - Working with Fragments
Can Elmas
 
Navigation Architecture Component
Navigation Architecture Component
Yasutaka Kawamoto
 
Embracing YUI3 and Frontend Perf
Embracing YUI3 and Frontend Perf
Morgan Cheng
 
Simplified Android Development with Simple-Stack
Simplified Android Development with Simple-Stack
Gabor Varadi
 
Google I/O 2021 Recap
Google I/O 2021 Recap
furusin
 
Introduction to android
Introduction to android
Arbuleac Eugeniu
 
Saindo da zona de conforto… resolvi aprender android
Saindo da zona de conforto… resolvi aprender android
Daniel Baccin
 
Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)
Gabor Varadi
 
Handling action bar in Android
Handling action bar in Android
indiangarg
 
Mini curso Android
Mini curso Android
Mario Jorge Pereira
 
Minicurso Android
Minicurso Android
Mario Jorge Pereira
 
Android por onde começar? Mini Curso Erbase 2015
Android por onde começar? Mini Curso Erbase 2015
Mario Jorge Pereira
 
Google Plus SignIn : l'Authentification Google
Google Plus SignIn : l'Authentification Google
Mathias Seguy
 
Quick Intro to Android Development
Quick Intro to Android Development
Jussi Pohjolainen
 
navigation-uiライブラリは、既存のアプリを置き換える ことができないかもしれない
navigation-uiライブラリは、既存のアプリを置き換える ことができないかもしれない
Yasutaka Kawamoto
 
Tips dan Third Party Library untuk Android - Part 1
Tips dan Third Party Library untuk Android - Part 1
Ibnu Sina Wardy
 

More Related Content

What's hot (20)

Material Design and Backwards Compatibility
Material Design and Backwards Compatibility
Angelo Rüggeberg
 
Implementing cast in android
Implementing cast in android
Angelo Rüggeberg
 
Introduction toandroid
Introduction toandroid
Google Developer Group Bucharest
 
Eddystone beacons demo
Eddystone beacons demo
Angelo Rüggeberg
 
droidparts
droidparts
Droidcon Berlin
 
Advancing the UI — Part 1: Look, Motion, and Gestures
Advancing the UI — Part 1: Look, Motion, and Gestures
Samsung Developers
 
Android - Working with Fragments
Android - Working with Fragments
Can Elmas
 
Navigation Architecture Component
Navigation Architecture Component
Yasutaka Kawamoto
 
Embracing YUI3 and Frontend Perf
Embracing YUI3 and Frontend Perf
Morgan Cheng
 
Simplified Android Development with Simple-Stack
Simplified Android Development with Simple-Stack
Gabor Varadi
 
Google I/O 2021 Recap
Google I/O 2021 Recap
furusin
 
Introduction to android
Introduction to android
Arbuleac Eugeniu
 
Saindo da zona de conforto… resolvi aprender android
Saindo da zona de conforto… resolvi aprender android
Daniel Baccin
 
Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)
Gabor Varadi
 
Handling action bar in Android
Handling action bar in Android
indiangarg
 
Mini curso Android
Mini curso Android
Mario Jorge Pereira
 
Minicurso Android
Minicurso Android
Mario Jorge Pereira
 
Android por onde começar? Mini Curso Erbase 2015
Android por onde começar? Mini Curso Erbase 2015
Mario Jorge Pereira
 
Google Plus SignIn : l'Authentification Google
Google Plus SignIn : l'Authentification Google
Mathias Seguy
 
Quick Intro to Android Development
Quick Intro to Android Development
Jussi Pohjolainen
 
Material Design and Backwards Compatibility
Material Design and Backwards Compatibility
Angelo Rüggeberg
 
Implementing cast in android
Implementing cast in android
Angelo Rüggeberg
 
Advancing the UI — Part 1: Look, Motion, and Gestures
Advancing the UI — Part 1: Look, Motion, and Gestures
Samsung Developers
 
Android - Working with Fragments
Android - Working with Fragments
Can Elmas
 
Navigation Architecture Component
Navigation Architecture Component
Yasutaka Kawamoto
 
Embracing YUI3 and Frontend Perf
Embracing YUI3 and Frontend Perf
Morgan Cheng
 
Simplified Android Development with Simple-Stack
Simplified Android Development with Simple-Stack
Gabor Varadi
 
Google I/O 2021 Recap
Google I/O 2021 Recap
furusin
 
Saindo da zona de conforto… resolvi aprender android
Saindo da zona de conforto… resolvi aprender android
Daniel Baccin
 
Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)
Gabor Varadi
 
Handling action bar in Android
Handling action bar in Android
indiangarg
 
Android por onde começar? Mini Curso Erbase 2015
Android por onde começar? Mini Curso Erbase 2015
Mario Jorge Pereira
 
Google Plus SignIn : l'Authentification Google
Google Plus SignIn : l'Authentification Google
Mathias Seguy
 
Quick Intro to Android Development
Quick Intro to Android Development
Jussi Pohjolainen
 

Similar to Android basic 4 Navigation Drawer (20)

navigation-uiライブラリは、既存のアプリを置き換える ことができないかもしれない
navigation-uiライブラリは、既存のアプリを置き換える ことができないかもしれない
Yasutaka Kawamoto
 
Tips dan Third Party Library untuk Android - Part 1
Tips dan Third Party Library untuk Android - Part 1
Ibnu Sina Wardy
 
STYLISH FLOOR
STYLISH FLOOR
ABU HASAN
 
Android Lollipop - Webinar am 11.12.2014
Android Lollipop - Webinar am 11.12.2014
inovex GmbH
 
Chapt 04 user interaction
Chapt 04 user interaction
Edi Faizal
 
A Single activity app with Jetpack's Navigation Component
A Single activity app with Jetpack's Navigation Component
Boonya Kitpitak
 
Action Bar in Android
Action Bar in Android
Prof. Erwin Globio
 
Navigation Architecture Component(京都Devかふぇ バージョン)
Navigation Architecture Component(京都Devかふぇ バージョン)
Yasutaka Kawamoto
 
What's New in Android
What's New in Android
Robert Cooper
 
Evolve 2014 - Effective Navigation in Xamarin Android
Evolve 2014 - Effective Navigation in Xamarin Android
James Montemagno
 
Getting Started With Material Design
Getting Started With Material Design
Yasin Yildirim
 
Android design patterns
Android design patterns
Platty Soft
 
Jetpack Navigation Component
Jetpack Navigation Component
James Shvarts
 
More Android UIs
More Android UIs
DENNIS JUNG
 
Android Support Library: Using ActionBarCompat
Android Support Library: Using ActionBarCompat
cbeyls
 
MenusAnddailogsinandroidddfdadusjsjdjdjs
MenusAnddailogsinandroidddfdadusjsjdjdjs
omkardolas3
 
Design Patterns for Tablets and Smartphones
Design Patterns for Tablets and Smartphones
Michael Galpin
 
Ionic2, les développeurs web à l'assaut du mobile, BDX I/O le 21/10/2016
Ionic2, les développeurs web à l'assaut du mobile, BDX I/O le 21/10/2016
Loïc Knuchel
 
Chapter 2 lesson-1 adding the action bar
Chapter 2 lesson-1 adding the action bar
Kalluri Vinay Reddy
 
Droidcon Moscow 2015. Support Design Library. Григорий Джанелидзе - e-Legion
Droidcon Moscow 2015. Support Design Library. Григорий Джанелидзе - e-Legion
Mail.ru Group
 
navigation-uiライブラリは、既存のアプリを置き換える ことができないかもしれない
navigation-uiライブラリは、既存のアプリを置き換える ことができないかもしれない
Yasutaka Kawamoto
 
Tips dan Third Party Library untuk Android - Part 1
Tips dan Third Party Library untuk Android - Part 1
Ibnu Sina Wardy
 
STYLISH FLOOR
STYLISH FLOOR
ABU HASAN
 
Android Lollipop - Webinar am 11.12.2014
Android Lollipop - Webinar am 11.12.2014
inovex GmbH
 
Chapt 04 user interaction
Chapt 04 user interaction
Edi Faizal
 
A Single activity app with Jetpack's Navigation Component
A Single activity app with Jetpack's Navigation Component
Boonya Kitpitak
 
Navigation Architecture Component(京都Devかふぇ バージョン)
Navigation Architecture Component(京都Devかふぇ バージョン)
Yasutaka Kawamoto
 
What's New in Android
What's New in Android
Robert Cooper
 
Evolve 2014 - Effective Navigation in Xamarin Android
Evolve 2014 - Effective Navigation in Xamarin Android
James Montemagno
 
Getting Started With Material Design
Getting Started With Material Design
Yasin Yildirim
 
Android design patterns
Android design patterns
Platty Soft
 
Jetpack Navigation Component
Jetpack Navigation Component
James Shvarts
 
More Android UIs
More Android UIs
DENNIS JUNG
 
Android Support Library: Using ActionBarCompat
Android Support Library: Using ActionBarCompat
cbeyls
 
MenusAnddailogsinandroidddfdadusjsjdjdjs
MenusAnddailogsinandroidddfdadusjsjdjdjs
omkardolas3
 
Design Patterns for Tablets and Smartphones
Design Patterns for Tablets and Smartphones
Michael Galpin
 
Ionic2, les développeurs web à l'assaut du mobile, BDX I/O le 21/10/2016
Ionic2, les développeurs web à l'assaut du mobile, BDX I/O le 21/10/2016
Loïc Knuchel
 
Chapter 2 lesson-1 adding the action bar
Chapter 2 lesson-1 adding the action bar
Kalluri Vinay Reddy
 
Droidcon Moscow 2015. Support Design Library. Григорий Джанелидзе - e-Legion
Droidcon Moscow 2015. Support Design Library. Григорий Джанелидзе - e-Legion
Mail.ru Group
 
Ad

More from Eakapong Kattiya (8)

(31 July 2013) iOS Basic Development Day 2 Human interface design
(31 July 2013) iOS Basic Development Day 2 Human interface design
Eakapong Kattiya
 
Evrdi : Social Diary ( iOS and Android )
Evrdi : Social Diary ( iOS and Android )
Eakapong Kattiya
 
Android Basic Development Day 1 Introduction & ADT
Android Basic Development Day 1 Introduction & ADT
Eakapong Kattiya
 
iOS Basic Development Day 2 - Objective-C 2.0 & iOS Framework
iOS Basic Development Day 2 - Objective-C 2.0 & iOS Framework
Eakapong Kattiya
 
(1 July 2013) iOS Basic Development Day 5 - Submit to App Store
(1 July 2013) iOS Basic Development Day 5 - Submit to App Store
Eakapong Kattiya
 
Iphone developer advance twitter
Iphone developer advance twitter
Eakapong Kattiya
 
iOS Advance Development - Social Media
iOS Advance Development - Social Media
Eakapong Kattiya
 
Iphone developer advance location based
Iphone developer advance location based
Eakapong Kattiya
 
(31 July 2013) iOS Basic Development Day 2 Human interface design
(31 July 2013) iOS Basic Development Day 2 Human interface design
Eakapong Kattiya
 
Evrdi : Social Diary ( iOS and Android )
Evrdi : Social Diary ( iOS and Android )
Eakapong Kattiya
 
Android Basic Development Day 1 Introduction & ADT
Android Basic Development Day 1 Introduction & ADT
Eakapong Kattiya
 
iOS Basic Development Day 2 - Objective-C 2.0 & iOS Framework
iOS Basic Development Day 2 - Objective-C 2.0 & iOS Framework
Eakapong Kattiya
 
(1 July 2013) iOS Basic Development Day 5 - Submit to App Store
(1 July 2013) iOS Basic Development Day 5 - Submit to App Store
Eakapong Kattiya
 
Iphone developer advance twitter
Iphone developer advance twitter
Eakapong Kattiya
 
iOS Advance Development - Social Media
iOS Advance Development - Social Media
Eakapong Kattiya
 
Iphone developer advance location based
Iphone developer advance location based
Eakapong Kattiya
 
Ad

Recently uploaded (20)

AI VIDEO MAGAZINE - June 2025 - r/aivideo
AI VIDEO MAGAZINE - June 2025 - r/aivideo
1pcity Studios, Inc
 
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
pcprocore
 
Curietech AI in action - Accelerate MuleSoft development
Curietech AI in action - Accelerate MuleSoft development
shyamraj55
 
MuleSoft for AgentForce : Topic Center and API Catalog
MuleSoft for AgentForce : Topic Center and API Catalog
shyamraj55
 
EIS-Webinar-Engineering-Retail-Infrastructure-06-16-2025.pdf
EIS-Webinar-Engineering-Retail-Infrastructure-06-16-2025.pdf
Earley Information Science
 
10 Key Challenges for AI within the EU Data Protection Framework.pdf
10 Key Challenges for AI within the EU Data Protection Framework.pdf
Priyanka Aash
 
The Future of Technology: 2025-2125 by Saikat Basu.pdf
The Future of Technology: 2025-2125 by Saikat Basu.pdf
Saikat Basu
 
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
 
Cyber Defense Matrix Workshop - RSA Conference
Cyber Defense Matrix Workshop - RSA Conference
Priyanka Aash
 
9-1-1 Addressing: End-to-End Automation Using FME
9-1-1 Addressing: End-to-End Automation Using FME
Safe Software
 
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
Fwdays
 
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
revolcs10
 
Mastering AI Workflows with FME by Mark Döring
Mastering AI Workflows with FME by Mark Döring
Safe Software
 
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Nilesh Gule
 
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
yosra Saidani
 
Cracking the Code - Unveiling Synergies Between Open Source Security and AI.pdf
Cracking the Code - Unveiling Synergies Between Open Source Security and AI.pdf
Priyanka Aash
 
"Database isolation: how we deal with hundreds of direct connections to the d...
"Database isolation: how we deal with hundreds of direct connections to the d...
Fwdays
 
OpenPOWER Foundation & Open-Source Core Innovations
OpenPOWER Foundation & Open-Source Core Innovations
IBM
 
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Priyanka Aash
 
UserCon Belgium: Honey, VMware increased my bill
UserCon Belgium: Honey, VMware increased my bill
stijn40
 
AI VIDEO MAGAZINE - June 2025 - r/aivideo
AI VIDEO MAGAZINE - June 2025 - r/aivideo
1pcity Studios, Inc
 
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
pcprocore
 
Curietech AI in action - Accelerate MuleSoft development
Curietech AI in action - Accelerate MuleSoft development
shyamraj55
 
MuleSoft for AgentForce : Topic Center and API Catalog
MuleSoft for AgentForce : Topic Center and API Catalog
shyamraj55
 
EIS-Webinar-Engineering-Retail-Infrastructure-06-16-2025.pdf
EIS-Webinar-Engineering-Retail-Infrastructure-06-16-2025.pdf
Earley Information Science
 
10 Key Challenges for AI within the EU Data Protection Framework.pdf
10 Key Challenges for AI within the EU Data Protection Framework.pdf
Priyanka Aash
 
The Future of Technology: 2025-2125 by Saikat Basu.pdf
The Future of Technology: 2025-2125 by Saikat Basu.pdf
Saikat Basu
 
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
 
Cyber Defense Matrix Workshop - RSA Conference
Cyber Defense Matrix Workshop - RSA Conference
Priyanka Aash
 
9-1-1 Addressing: End-to-End Automation Using FME
9-1-1 Addressing: End-to-End Automation Using FME
Safe Software
 
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
Fwdays
 
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
revolcs10
 
Mastering AI Workflows with FME by Mark Döring
Mastering AI Workflows with FME by Mark Döring
Safe Software
 
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Nilesh Gule
 
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
yosra Saidani
 
Cracking the Code - Unveiling Synergies Between Open Source Security and AI.pdf
Cracking the Code - Unveiling Synergies Between Open Source Security and AI.pdf
Priyanka Aash
 
"Database isolation: how we deal with hundreds of direct connections to the d...
"Database isolation: how we deal with hundreds of direct connections to the d...
Fwdays
 
OpenPOWER Foundation & Open-Source Core Innovations
OpenPOWER Foundation & Open-Source Core Innovations
IBM
 
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Priyanka Aash
 
UserCon Belgium: Honey, VMware increased my bill
UserCon Belgium: Honey, VMware increased my bill
stijn40
 

Android basic 4 Navigation Drawer

  • 1. Navigation Drawer by Eakapong Kattiya http://developer.android.com/training/implementing-navigation/nav-drawer.html Monday, July 15, 13
  • 2. by Eakapong Kattiya Navigation Drawer :Add ActionbarSherlock Library Source : MyNavigationDrawer.zip Monday, July 15, 13
  • 3. by Eakapong Kattiya Navigation Drawer :Add ActionbarSherlock Library Monday, July 15, 13
  • 4. by Eakapong Kattiya (1)Theme.Sherlock : styles.xml <resources> <style name="AppBaseTheme" parent="Theme.Sherlock.Light"> </style> <style name="AppTheme" parent="AppBaseTheme"> </style> </resources> Change AppBaseTheme in styles.xml Monday, July 15, 13
  • 5. by Eakapong Kattiya (2)Theme.Sherlock :AndroidManifest.xml <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" //.. <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.example.mydrawerlayout.MainActivity" android:label="@string/app_name" android:theme="@style/Theme.Sherlock" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> Monday, July 15, 13
  • 6. by Eakapong Kattiya Navigation Drawer : activity_main.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" //.. <android.support.v4.widget.DrawerLayout android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent" > <!-- The main content view --> <FrameLayout android:id="@+id/content_frame" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#FF00FF" /> <!-- The navigation drawer --> <ListView android:id="@+id/left_drawer" android:layout_width="240dp" android:layout_height="match_parent" android:layout_gravity="start" android:background="#FFFFFF" android:choiceMode="singleChoice" android:divider="@android:color/transparent" android:dividerHeight="0dp" /> </android.support.v4.widget.DrawerLayout> </RelativeLayout> Monday, July 15, 13
  • 7. by Eakapong Kattiya Navigation Drawer : main.xml <menu xmlns:android="http://schemas.android.com/apk/res/android" > <item android:id="@+id/action_settings" android:orderInCategory="100" android:showAsAction="never" android:title="@string/action_settings"/> <item android:id="@+id/action_websearch" android:icon="@drawable/action_search" android:showAsAction="ifRoom|withText" android:title="Search"/> </menu> Monday, July 15, 13
  • 8. import com.actionbarsherlock.app.SherlockFragmentActivity; //import android.app.Activity; public class MainActivity extends SherlockFragmentActivity implements OnItemClickListener{ List<Integer> images = new ArrayList<Integer>(); List<String> items = new ArrayList<String>(); private ListView mDrawerList; private DrawerLayout mDrawerLayout; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); images.add(android.R.drawable.ic_menu_gallery); images.add(android.R.drawable.ic_menu_camera); items.add("Earth"); items.add("Jupiter"); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); // Set Shadow mDrawerList = (ListView) findViewById(R.id.left_drawer); ListAdapter adapter = new CustomArrayAdapter(this, items, images); // Set the adapter for the list view mDrawerList.setAdapter(adapter); mDrawerList.setOnItemClickListener(this); if (savedInstanceState == null) { selectItem(0); } } } by Eakapong Kattiya Navigation Drawer : MainActivity.java Monday, July 15, 13
  • 9. import com.actionbarsherlock.view.Menu; //import android.view.Menu; public class MainActivity extends SherlockFragmentActivity implements OnItemClickListener{ //.. @Override public boolean onCreateOptionsMenu(Menu menu) { //getMenuInflater().inflate(R.menu.main, menu); getSupportMenuInflater().inflate(R.menu.main, menu); return true; } } by Eakapong Kattiya Navigation Drawer : MainActivity.java Monday, July 15, 13
  • 10. import com.actionbarsherlock.view.Menu; //import android.view.Menu; public class MainActivity extends SherlockFragmentActivity implements OnItemClickListener{ //.. @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { selectItem(arg2); } private void selectItem(int arg0) { // update the main content by replacing fragments PlanetFragment fragment = new PlanetFragment(); fragment.setPlanet(items.get(arg0)); FragmentManager fragmentManager = getSupportFragmentManager(); fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit(); // update selected item and title, then close the drawer mDrawerList.setItemChecked(position, true); mDrawerLayout.closeDrawer(mDrawerList); } } by Eakapong Kattiya Navigation Drawer : MainActivity.java Monday, July 15, 13
  • 11. import com.actionbarsherlock.view.Menu; //import android.view.Menu; public class MainActivity extends SherlockFragmentActivity implements OnItemClickListener{ //.. @Override public boolean onOptionsItemSelected(final MenuItem item) { // Handle action buttons switch (item.getItemId()) { case R.id.action_websearch: // create intent to perform web search for this planet Intent intent = new Intent(Intent.ACTION_WEB_SEARCH); intent.putExtra(SearchManager.QUERY, getSupportActionBar().getTitle()); startActivity(intent); return true; default: return super.onOptionsItemSelected(item); } } } by Eakapong Kattiya Navigation Drawer : MainActivity.java Monday, July 15, 13
  • 12. public class CustomArrayAdapter extends ArrayAdapter<String> { private List<Integer> images; private List<String> items; private Context context; public CustomArrayAdapter(Context context, List<String> items, List<Integer> images) { super(context, R.layout.drawer_list_item, items); this.context = context; this.images = images; this.items = items ; } @Override public View getView(int arg0, View convertView, ViewGroup parent) { /* create a new view of my layout and inflate it in the row */ LayoutInflater inflator = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = inflator.inflate(R.layout.drawer_list_item, null); TextView textView = (TextView) view.findViewById(R.id.cityName); textView.setText(items.get(arg0)); ImageView imageCity = (ImageView) view.findViewById(R.id.imageCity); String packageName = context.getPackageName(); String imageName = items.get(position).toLowerCase(); int resId = context.getResources().getIdentifier(imageName,"drawable", packageName); imageCity.setImageResource(resId); return view; } } by Eakapong Kattiya Navigation Drawer : CustomArrayAdapter.java Monday, July 15, 13
  • 13. <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="80dip" android:background="#222222" > <ImageView android:id="@+id/imageCity" android:layout_width="50dp" android:layout_height="50dp" /> <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_toRightOf="@id/imageCity" android:orientation="vertical" android:paddingLeft="10dp" > <TextView android:id="@+id/cityName" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textColor="#FFFFFF" android:textSize="18dp" /> <TextView android:id="@+id/cityLink" android:layout_width="fill_parent" android:layout_height="wrap_content" android:autoLink="web" android:textColor="#FFFFFF" android:textSize="14dp" /> </LinearLayout> </RelativeLayout> by Eakapong Kattiya Navigation Drawer : drawer_list_item.xml Monday, July 15, 13
  • 14. by Eakapong Kattiya List vs ArrayList vs LinkedList List is interface , not a concrete class. List cannot be instantiated. List<String> items = new List<String>() ; ArrayList is an implementation of List. List<String> items = new ArrayList<String>(); items.add("Earth"); items.add("Jupiter"); LinkedList is an implementation of List. List<String> items = new LinkedList<String>(); items.add("Earth"); items.add("Jupiter"); Monday, July 15, 13
  • 15. by Eakapong Kattiya ArrayList vs LinkedList - ส่วนใหญ่แล้วใช้ ArrayList - ใช้ LinkedList เมื่อข้อมูลใหญ่มากเช่น เกิน 1 ล้านแถวจะทํางานเร็วกว่า (Big-Oh น้อยกว่าเมื่อมีการเพิ่มข้อมูล) http://leepoint.net/notes-java/algorithms/big-oh/bigoh.html Algorithm array ArrayList LinkedList access front O(1) O(1) access back O(1) O(1) access middle O(1) O(N) insert at front O(N) O(1) insert at back O(1) O(1) insert in middle O(N) O(1) Monday, July 15, 13
  • 16. by Eakapong Kattiya Sort ArrayList List<String> items = new ArrayList<String>(); items.add("Earth"); items.add("Jupiter"); Collections.sort(items); //Ascending Sort Comparator<String> comparator = Collections.reverseOrder(); Collections.sort(items,comparator); //Descending Sort Monday, July 15, 13
  • 17. -Fragment is a chunk of user interface with its own life cycle. -Fragment must exist within an Activity. -Interaction with fragments is done through FragmentManager. -Fragment API was introduced in API 11 -Use SherlockFragmentActivity , SherlockFragment instead of native Fragment API by Eakapong Kattiya Fragment (>API 11) Monday, July 15, 13
  • 18. by Eakapong Kattiya Fragment (>API 11) Monday, July 15, 13
  • 19. by Eakapong Kattiya Navigation Drawer : fragment_planet.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" > <ImageView android:id="@+id/image" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#000000" android:gravity="center" android:padding="32dp" /> </RelativeLayout> Monday, July 15, 13
  • 20. public class PlanetFragment extends SherlockFragment { private String planet ; public PlanetFragment() { } public String getPlanet() { return planet; } public void setPlanet(String planet) { this.planet = planet; } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_planet, container, false); String packageName = getActivity().getPackageName(); String imageName = planet.toLowerCase(); int imageId = getResources().getIdentifier(imageName,"drawable", packageName); ImageView imageView = (ImageView)view.findViewById(R.id.image); imageView.setImageResource(imageId); getActivity().setTitle(planet); return view; } } by Eakapong Kattiya Navigation Drawer : PlanetFragment.java Monday, July 15, 13
  • 21. ImageView imageCity = (ImageView) view.findViewById(R.id.imageCity); Drawable image = context.getResources().getDrawable(android.R.drawable.ic_dialog_email); imageCity.setImageDrawable(image); by Eakapong Kattiya ImageView List<Integer> images = new ArrayList<Integer>(); images.add(android.R.drawable.ic_menu_gallery); images.add(android.R.drawable.ic_menu_camera); ImageView imageCity = (ImageView) view.findViewById(R.id.imageCity); Drawable image = context.getResources().getDrawable(images.get(0)); imageCity.setImageDrawable(image); ImageView imageCity = (ImageView) view.findViewById(R.id.imageCity); String packageName = context.getPackageName(); String imageName = items.get(position).toLowerCase(); int resId = context.getResources().getIdentifier(imageName,"drawable", packageName); imageCity.setImageResource(resId); Fixed Resource id Dynamic Resource id Choose image name Monday, July 15, 13
  • 22. by Eakapong Kattiya Nine-patch Image Monday, July 15, 13
  • 23. by Eakapong Kattiya Nine-patch Image Monday, July 15, 13
  • 24. by Eakapong Kattiya Nine-patch Image res/drawable/drawer_shadow.9.png Monday, July 15, 13
  • 25. by Eakapong Kattiya Navigation Drawer with ActionBarDrawerToggle Source : MyNavigationDrawerToggle.zip Monday, July 15, 13