AndroidDevelopersのチュートリアルのNotepad Exercise 1を実行します。
【手順1】
1.「(AndroidDevelopersチュートリアル)Notepad Tutorialの準備」でダウンロードし、解凍した「Notepadv1」のディレクトリを選択し、右クリックから「コピー」を選択。
1.「Eclipse」のワークスペースのディレクトリに移動し、「Ctrl+V」で貼り付け。
1.「Eclipse 3.7.2 Indigoの起動方法」でEclipseを起動。
2.メニューから「ファイル」⇒「新規」⇒「プロジェクト」を選択。
1.「Android」⇒「Androidプロジェクト」を選択。
2.「次へ」ボタンをクリック。
1.「外部ファイルからプロジェクトを作成」を選択。
2.「Location」の参照ボタンをクリックし、【手順2】でコピーを貼り付けたディレクトリを選択。
3.「次へ」ボタンをクリック。
1.「ターゲット名」は「Android1.5」を選択。
2.「次へ」ボタンをクリック。
1.「完了」ボタンをクリック。
1.以下のようにプロジェクトが読み込まれます。
【手順9】
1.「res/layout/notepad_list.xml」を以下の様に入力。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ListView
android:id="@android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@android:id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/no_notes" />
</LinearLayout>
3.「Ctrl+Shift+F」を押し、ソースコードをフォーマッティング。
4.「任意のファイルの作成方法」の手順で、「res/layout/」ディレクトリに「notes_row.xml」というファイルを作成。
5.「res/layout/notes_row.xml」を以下の様に入力。
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
6.「Ctrl+Shift+F」を押し、ソースコードをフォーマッティング。
7.「res/values/strings.xml」を以下の様に入力。
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Notepad v1</string>
<string name="no_notes">No Notes Yet</string>
<string name="menu_insert">Add Item</string>
</resources>
8.「Ctrl+Shift+F」を押し、ソースコードをフォーマッティング。
9.「Notepadv1.java」を以下の様に入力。
/*
* Copyright (C) 2008 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.demo.notepad1;
import android.app.ListActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.SimpleCursorAdapter;
public class Notepadv1 extends ListActivity {
public static final int INSERT_ID = Menu.FIRST;
private NotesDbAdapter mDbHelper;
private int mNoteNumber = 1;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.notepad_list);
mDbHelper = new NotesDbAdapter(this);
mDbHelper.open();
fillData();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
boolean result = super.onCreateOptionsMenu(menu);
menu.add(0, INSERT_ID, 0, R.string.menu_insert);
return result;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case INSERT_ID:
createNote();
return true;
}
return super.onOptionsItemSelected(item);
}
private void createNote() {
String noteName = "Note " + mNoteNumber++;
mDbHelper.createNote(noteName, "");
fillData();
}
private void fillData() {
// Get all of the notes from the database and create the item list
Cursor c = mDbHelper.fetchAllNotes();
startManagingCursor(c);
String[] from = new String[] { NotesDbAdapter.KEY_TITLE };
int[] to = new int[] { R.id.text1 };
// Now create an array adapter and set it to display using our row
SimpleCursorAdapter notes = new SimpleCursorAdapter(this,
R.layout.notes_row, c, from, to);
setListAdapter(notes);
}
}
10.「Ctrl+Shift+F」を押し、ソースコードをフォーマッティング。
【手順10】
1.「Androidプロジェクトの実行方法」の手順で、「Androidプロジェクト」を実行。
2.エミュレータが起動しロックを解除し、以下の様にアプリケーションが実行されます。
3.「MENU」ボタンをクリックすると、画面下にメニューが表示されます。
1.メニューの「Add Item」をクリックするとリストにノートの名前が追加されます。
以上です。
Notepad+Exercise+1-01.jpg)
Notepad+Exercise+1-02.jpg)
Notepad+Exercise+1-03.jpg)
Notepad+Exercise+1-04.jpg)
Notepad+Exercise+1-05.jpg)
Notepad+Exercise+1-06.jpg)
Notepad+Exercise+1-07.jpg)
Notepad+Exercise+1-08.jpg)
Notepad+Exercise+1-09.jpg)
Notepad+Exercise+1-10.jpg)
0 件のコメント:
コメントを投稿
注: コメントを投稿できるのは、このブログのメンバーだけです。