• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Activity
 

Activity

on

  • 173 views

Android App Dev lesson serial - Activity

Android App Dev lesson serial - Activity

Statistics

Views

Total Views
173
Views on SlideShare
173
Embed Views
0

Actions

Likes
0
Downloads
3
Comments
0

0 Embeds 0

No embeds

Accessibility

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Activity Activity Presentation Transcript

    • Activity Michael Pan
    • The project
    • Blank Activity
    • Layout - activity_record.xml
    • Project View
    • AndroidManifest.xml DailyRecord > app > src > main > AndroidManifest.xml
    • Application attributes <?xml version="1.0" encoding="utf-8"?>! <manifest xmlns:android="http://schemas.android.com/apk/res/android"! package="com.zencher.dailyrecord.app" >! ! <application! android:allowBackup="true" ! android:icon="@drawable/ic_launcher"! android:label="@string/app_name"! android:theme="@style/AppTheme" >! <activity! android:name="com.zencher.dailyrecord.app.RecordActivity"! android:label="@string/app_name" >! <intent-filter>! <action android:name="android.intent.action.MAIN" />! ! <category android:name="android.intent.category.LAUNCHER" />! </intent-filter>! </activity>! </application>! ! </manifest> http://bit.ly/1msJ804 Backup App image
    • Change icon @drawable/ic_launcher app > src > main > res > drawable-xxxx
    • Run - Change Icon
    • Application attributes - android:label <?xml version="1.0" encoding="utf-8"?>! <manifest xmlns:android="http://schemas.android.com/apk/res/android"! package="com.zencher.dailyrecord.app" >! ! <application! android:allowBackup="true" ! android:icon="@drawable/ic_launcher"! android:label="@string/app_name"! android:theme="@style/AppTheme" >! <activity! android:name="com.zencher.dailyrecord.app.RecordActivity"! android:label="@string/app_name" >! <intent-filter>! <action android:name="android.intent.action.MAIN" />! ! <category android:name="android.intent.category.LAUNCHER" />! </intent-filter>! </activity>! </application>! ! </manifest>
    • Another resource @string/app_name app > src > main > res > values > strings.xml
    • Tag - activity <?xml version="1.0" encoding="utf-8"?>! <manifest xmlns:android="http://schemas.android.com/apk/res/android"! package="com.zencher.dailyrecord.app" >! ! <application! android:allowBackup="true" ! android:icon="@drawable/ic_launcher"! android:label="@string/app_name"! android:theme="@style/AppTheme" >! <activity! android:name="com.zencher.dailyrecord.app.RecordActivity"! android:label="@string/app_name" >! <intent-filter>! <action android:name="android.intent.action.MAIN" />! ! <category android:name="android.intent.category.LAUNCHER" />! </intent-filter>! </activity>! </application>! ! </manifest> Class name
    • activity - android:label <?xml version="1.0" encoding="utf-8"?>! <manifest xmlns:android="http://schemas.android.com/apk/res/android"! package="com.zencher.dailyrecord.app" >! ! <application! android:allowBackup="true" ! android:icon="@drawable/ic_launcher"! android:label="@string/app_name"! android:theme="@style/AppTheme" >! <activity! android:name="com.zencher.dailyrecord.app.RecordActivity"! android:label="@string/app_name" >! <intent-filter>! <action android:name="android.intent.action.MAIN" />! ! <category android:name="android.intent.category.LAUNCHER" />! </intent-filter>! </activity>! </application>! ! </manifest>
    • Create a new string tag
    • Run @string/main_activity_label
    • intent-filter <?xml version="1.0" encoding="utf-8"?>! <manifest xmlns:android="http://schemas.android.com/apk/res/android"! package="com.zencher.dailyrecord.app" >! ! <application! android:allowBackup="true" ! android:icon="@drawable/ic_launcher"! android:label="@string/app_name"! android:theme="@style/AppTheme" >! <activity! android:name="com.zencher.dailyrecord.app.RecordActivity"! android:label="@string/app_name" >! <intent-filter>! <action android:name="android.intent.action.MAIN" />! ! <category android:name="android.intent.category.LAUNCHER" />! </intent-filter>! </activity>! </application>! ! </manifest>
    • intent Message among activities intent-filter filter intent event must have a action android.intent.action.MAIN - the initial activity category android.intent.category.LAUNCHER - Should be displayed in the top-level launcher
    • Add some Control EditText Button
    • activity_record.xml in layout app > src > main > res > layout > activity_record.xml <RelativeLayout >! ! <TextView />! ! <EditText />! ! <Button />! ! </RelativeLayout>
    • Design & Text - layout xml Design Text
    • RecordActivity.java app > src > main > java > (domain) > RecordActivity.java public class RecordActivity extends Activity {! ! @Override! protected void onCreate(Bundle savedInstanceState) {! super.onCreate(savedInstanceState);! setContentView(R.layout.activity_record);! } ! ! ! // ignored… ! }
    • R Auto generated Class files in res/ will be the field in R app > build > source > r > debug > (domain) > R
    • layout xml in R
    • Compiling process res/ AndroidManifest.xml R.java Asset Packaging Tool (aapt) src/ RecordActivity.java Compile Java Java bytecode .classCross Compile to Dalvik Dalvik bytecode .dex Compiled Resource Build & Sign apk Android Package .apk Install & Run
    • setContentView(R.layout.activity_record); <RelativeLayout >! ! <TextView />! ! <EditText />! ! <Button />! ! </RelativeLayout> ClassLoader.loadClass(“RelativeLayout”) RelativeLayout ClassLoader.loadClass(“TextView”) TextView EditText Button ClassLoader.loadClass(“EditText”) ClassLoader.loadClass(“Button”)
    • Run
    • Get instance into variable
    • import class option + Enter
    • EditText & Button
    • Get instance in Activity findViewById() protected void onCreate(Bundle savedInstanceState) {! super.onCreate(savedInstanceState);! setContentView(R.layout.activity_record);! mTopTextView = (TextView) findViewById(R.id.textView);! } activity_record.xml
    • Apply into three variables
    • OnClickListener
    • View.OnClickListener new View.OnClickListener() {! ! @Override! ! public void onClick(View v) {! ! ! mTopTextView.setText(mInputView.getText());! ! }! }
    • Question