Android Crashcourse@AlexeyBuzdin 15.06.2013
AndroidJava SE + Android.jarDalvik runtimeComponent based MVC
Project Structure
Project StructureSource code in JavaImages, gradients, etcUI written in XMLReference Data (Strings, colors, arrays)App con...
Activity
Activitypublic class TestActivity extends Activity {@Overrideprotected void onCreate(Bundle savedState) {super.onCreate(sa...
Activity states
ContextInterface to global information about anapplication environment.Up-calls for application-level operations suchas la...
Context examplesTextView text = new TextView(context);new ArrayAdapter(context, R.layout.item, myList)context.getExternalC...
R.javapublic class TestActivity extends Activity {@Overrideprotected void onCreate(Bundle savedState) {super.onCreate(save...
R.java (resource)Auto generated interface between src and androidresources. Used only for compilation time.
R.java
Project Structure
Views
ViewsViews - TextView, EditText, Button ...ViewGroup - LinearLayout, RelativeLayout ...AdapterView - Spinner, Gallery, Lis...
res/layout/<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"a...
res/layout/<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:l...
res/layout/
Views. Java part@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContent...
Views. Java part@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContent...
Under the hood. LayoutInflaterLayoutInflater inflater = context.getLayoutInflater();View view = inflater.inflate(R.layout....
Under the hood. LayoutInflater@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceSta...
Event HandlingButton button = new Button(context);button.setOnClickListener(new OnClickListener(){@Overridepublic void onC...
Event HandlingFor ViewsOnLongClickListenerOnSelectListenerOnHoverListener.....For AdapterViewOnItemClickListenerOnItemLong...
TextView
ListView?
Adapter
AdapterViewGallery gallery = (Gallery) findViewById(R.id.gallery);ArrayList<String> list = new ArrayList<String>();gallery...
IntentAbstract description of an operation to be performed.External IntentsOpen URLCall a PersonShare an ImageInternal Int...
ExampleIntent intent = new Intent(context, SecondActivity.class);startActivity(intent);Intent intent = new Intent(context,...
Exampleprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.arti...
AndroidManifest<manifest xmlns:android="http://schemas.android.com/apk/res/android"package="lv.ldn.rssreader"android:versi...
AndroidManifest<manifest xmlns:android="http://schemas.android.com/apk/res/android"package="lv.ldn.rssreader"android:versi...
AsyncTaskpublic class MyTask extends AsyncTask<Integer, Void, String>{protected void onPreExecute() {}protected String doI...
AsyncTaskMyTask task = new MyTask();task.execute(value)
Upcoming SlideShare
Loading in...5
×

Android crashcourse

977

Published on

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
977
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Transcript of "Android crashcourse"

  1. 1. Android Crashcourse@AlexeyBuzdin 15.06.2013
  2. 2. AndroidJava SE + Android.jarDalvik runtimeComponent based MVC
  3. 3. Project Structure
  4. 4. Project StructureSource code in JavaImages, gradients, etcUI written in XMLReference Data (Strings, colors, arrays)App config file
  5. 5. Activity
  6. 6. Activitypublic class TestActivity extends Activity {@Overrideprotected void onCreate(Bundle savedState) {super.onCreate(savedState);setContentView(R.layout.main);}}
  7. 7. Activity states
  8. 8. ContextInterface to global information about anapplication environment.Up-calls for application-level operations suchas launching activities, broadcasting andreceiving intents, etc.
  9. 9. Context examplesTextView text = new TextView(context);new ArrayAdapter(context, R.layout.item, myList)context.getExternalCacheDir()context.getResources()context.startActivity(navigationIntent)
  10. 10. R.javapublic class TestActivity extends Activity {@Overrideprotected void onCreate(Bundle savedState) {super.onCreate(savedState);setContentView(R.layout.main);}}
  11. 11. R.java (resource)Auto generated interface between src and androidresources. Used only for compilation time.
  12. 12. R.java
  13. 13. Project Structure
  14. 14. Views
  15. 15. ViewsViews - TextView, EditText, Button ...ViewGroup - LinearLayout, RelativeLayout ...AdapterView - Spinner, Gallery, ListView ...
  16. 16. res/layout/<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="match_parent"android:layout_height="match_parent"></LinearLayout>
  17. 17. res/layout/<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="match_parent"android:layout_height="match_parent"><TextView android:id="@+id/textView"android:layout_height="wrap_content"android:layout_width="wrap_content"android:text="@string/app_name"/></LinearLayout>
  18. 18. res/layout/
  19. 19. Views. Java part@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);TextView text = (TextView) findViewById(R.id.textView);}
  20. 20. Views. Java part@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);TextView text = (TextView) findViewById(R.id.textView);text.findViewById(0); // same method invocation}
  21. 21. Under the hood. LayoutInflaterLayoutInflater inflater = context.getLayoutInflater();View view = inflater.inflate(R.layout.main, null);
  22. 22. Under the hood. LayoutInflater@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);LayoutInflater inflater = context.getLayoutInflater();View view = inflater.inflate(R.layout.main, null);setContentView(view);TextView text = (TextView) view.findViewById(R.id.textView);}
  23. 23. Event HandlingButton button = new Button(context);button.setOnClickListener(new OnClickListener(){@Overridepublic void onClick(View v){Toast.makeText(MyActivity.this, "HelloWorld", Toast.LENGTH_SHORT).show();}});
  24. 24. Event HandlingFor ViewsOnLongClickListenerOnSelectListenerOnHoverListener.....For AdapterViewOnItemClickListenerOnItemLongClickListener
  25. 25. TextView
  26. 26. ListView?
  27. 27. Adapter
  28. 28. AdapterViewGallery gallery = (Gallery) findViewById(R.id.gallery);ArrayList<String> list = new ArrayList<String>();gallery.setAdapter(new ArrayAdapter<String>(this, 0, list){@Overridepublic View getView(int position, View convertView,ViewGroup parent) {// 1. Check if view already exists// 2. If not - Inflate view// 3. Populate viewreturn view;}});
  29. 29. IntentAbstract description of an operation to be performed.External IntentsOpen URLCall a PersonShare an ImageInternal IntentsStart Activity
  30. 30. ExampleIntent intent = new Intent(context, SecondActivity.class);startActivity(intent);Intent intent = new Intent(context, SecondActivity.class);intent.putExtra("url", url);intent.putExtra("bean", serializable);startActivity(intent);
  31. 31. Exampleprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.article_detail);String s = getIntent().getStringExtra("url");Bean b = (Bean)getIntent().getSerializableExtra("bean");}
  32. 32. AndroidManifest<manifest xmlns:android="http://schemas.android.com/apk/res/android"package="lv.ldn.rssreader"android:versionCode="1"android:versionName="1.0" ><uses-sdk android:minSdkVersion="7" android:targetSdkVersion="16" /><uses-permission android:name="android.permission.INTERNET" /><application android:icon="@drawable/starred" android:label="@string/app_name"><activity android:name=".MyActivity"><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter></activity></application></manifest>
  33. 33. AndroidManifest<manifest xmlns:android="http://schemas.android.com/apk/res/android"package="lv.ldn.rssreader"android:versionCode="1"android:versionName="1.0" ><uses-sdk android:minSdkVersion="7" android:targetSdkVersion="16" /><uses-permission android:name="android.permission.INTERNET" /><application android:icon="@drawable/starred" android:label="@string/app_name"><activity android:name=".MyActivity"><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter></activity><activity android:name=".SecondActivity"/></application></manifest>
  34. 34. AsyncTaskpublic class MyTask extends AsyncTask<Integer, Void, String>{protected void onPreExecute() {}protected String doInBackground(Integer... integers) {return null;}protected void onPostExecute(String result) {}}
  35. 35. AsyncTaskMyTask task = new MyTask();task.execute(value)

×