Sunday, February 20, 2011

Android Development Study Notes 2 - Opiton Menus

strings.xml

<?xml version="1.0" encoding="utf-8"?>

<resources>

<string name="AllDepartment">List All Depts</string>

<string name="Seach">Search</string>

</resources>

Add the following codes in the activity class


@Override

public boolean onCreateOptionsMenu(Menu menu) {

          menu.add(0, 0, 0,this.getResources().getString(R.string.AllDepartment));

          menu.add(0, 1, 1, this.getResources().getString(R.string.Seach));

return super.onCreateOptionsMenu(menu);

    }

When user click on "menu" button, 2 option menus would appear at the bottom of the screen.

Android Study Notes 1 - "Hello World"

"Hello World"

strings.xml

<?xml version="1.0" encoding="utf-8"?>

<resources>

<string name="hello">Hello World, DroidActivity!</string>

<string name="app_name">Droid1</string>

<string name="hello1">你好!</string>

</resources>

main.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

>

<TextView

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="@string/hello"

/>

<TextView android:id="@+id/textView1"android:layout_width="wrap_content" android:layout_height="wrap_content"android:text="@string/hello1"></TextView>

</LinearLayout>

DroidAvtivity.java

package com.myandroid.droid1;
import android.app.Activity;
import android.os.Bundle;
public class DroidActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}