Upgrade to Pro — share decks privately, control downloads, hide ads and more …

android programming 1

android programming 1

this slides explain how to use android's activity and views

Giovanni De Francesco

January 11, 2013
Tweet

More Decks by Giovanni De Francesco

Other Decks in Programming

Transcript

  1. Second level: Views Every “brick” placed in your Activity. Examples

    (javaàAndroid): ›  JLabelàTextView ›  JButtonàButton ›  FlowLayoutàLinearLayout
  2. Activity UI <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http:// schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content"

    > <TextView android:id="@+id/tv1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" /> </RelativeLayout> Android Programming
  3. Activity Logic public class MainActivity extends Activity { @Override protected

    void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } @Override protected void onPause() { // TODO Auto-generated method stub super.onPause(); } } Android Programming
  4. Manifest File <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.firstapp” android:versionCode="1” android:versionName="1.0"

    > <uses-sdk android:minSdkVersion=”7” android:targetSdkVersion="16" /> <application android:icon="@drawable/ic_launcher” android:label="@string/app_name”> <activity android:name="com.example.firstapp.MainActivity" 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> Android Programming
  5. Working with Activities //first Activity Intent i = new Intent

    (MainActivity.this, NewActivity.class); i.putExtra("key", "value"); //called Activity Intent launcher = getIntent(); launcher.getExtras().getString("key"); Android Programming
  6. What should we do today? When the user clicks the

    button another activity will start. The second activity shows username and password Android Programming