Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Introducing Activity and Intent. 2 Memory LinearLayout, weight=2 LinearLayout, weight=1 TextView ListView.

Similar presentations


Presentation on theme: "1 Introducing Activity and Intent. 2 Memory LinearLayout, weight=2 LinearLayout, weight=1 TextView ListView."— Presentation transcript:

1 1 Introducing Activity and Intent

2 2 Memory LinearLayout, weight=2 LinearLayout, weight=1 TextView ListView

3 3 How to create xml file Right click (on the folder)

4 4 The menu.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent“ android:layout_height="fill_parent"> <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="2"> <TextView android:id="@+id/TextView01" android:layout_width="wrap_content” android:layout_height="wrap_content“ android:textSize="@dimen/screen_title_size" android:text="@string/menu" android:layout_gravity="center" android:shadowColor="@android:color/white" android:textColor="@color/title_color" />

5 5 The menu.xml cont. <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent“ android:layout_weight="1"> <ListView android:layout_height="wrap_content" android:id="@+id/list_menu" android:layout_width="fill_parent" android:layout_gravity="center_horizontal" android:divider="@drawable/divider" android:listSelector="@drawable/textured">

6 6 The dimens.xml (in values folder) 24pt 5pt 3pt 16pt 10pt 7pt 20px

7 7 The colors.xml (in values folder) #FFFF0F #f0f0f0 #1a1a48 #f0f0f0 #F00 #FFFF0F #F00

8 8 How to create java file Right click (on the folder)

9 9 How to override a method Right click on the code pane

10 10 How to override a method cont. Select the method to overridem eg, onCreate

11 11 The strings.xml (in values folder) …. Memory Settings Play Game View Scores Help …

12 12 Create ListView from resource ListView menuList = (ListView) findViewById(R.id.list_menu); String[] items = { getResources().getString(R.string.menu_item_play), getResources().getString(R.string.menu_item_scores), getResources().getString(R.string.menu_item_settings), getResources().getString(R.string.menu_item_help) }; ArrayAdapter adapt = new ArrayAdapter (this,R.layout.menu_item, items); menuList.setAdapter(adapt);

13 13 Starting an Activity class public class Memory extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.menu); ListView menuList = (ListView) findViewById(R.id.list_menu); String[] items = { getResources().getString(R.string.menu_item_play), getResources().getString(R.string.menu_item_scores), getResources().getString(R.string.menu_item_settings), getResources().getString(R.string.menu_item_help) }; ArrayAdapter adapt = new ArrayAdapter (this,R.layout.menu_item, items); menuList.setAdapter(adapt); menuList.setSelection(-1);

14 14 Starting an Activity class menuList.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView parent, View itemClicked, int position, long id) { // Note: if the list was built "by hand" the id could be used. // As-is, though, each item has the same id TextView textView = (TextView) itemClicked; String strText = textView.getText().toString(); if (strText.equalsIgnoreCase( getResources().getString(R.string.menu_item_play))) { startActivity(new Intent(Memory.this, MemoryPlayGame.class)); } else if (strText.equalsIgnoreCase(getResources().getString(R.string.menu_item_help))) { // startActivity(new Intent(Memory.this, MemoryHelp.class)); } }); }

15 15 Include the Activity in the manifest <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.plearn" android:versionCode="1" android:versionName="1.0">


Download ppt "1 Introducing Activity and Intent. 2 Memory LinearLayout, weight=2 LinearLayout, weight=1 TextView ListView."

Similar presentations


Ads by Google