ステップ 5
ListView でノートのリストを作成するためには、行ごとのビューの定義が必要です。
- res/layout の下にnotes_row.xmlという名前のファイルを作成します。
ルート要素は、TextView を選択し、完了をクリックします。 - 以下の内容に書き換えます。
<?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" > </TextView>
ステップ 6
Notepadv1.javaを開き、レイアウトのビューに対し機能を追加していきます。mNoteNumberは、ノートを作成する際の一時的なタイトルにつけるカウンタとして利用します。
onCreate メソッドは、アクティビティが開始された際に実行されます。
onCreateOptionsMenu メソッドは、アクティビティにメニューを追加するために使用します。ユーザが、ハードウェアのmenuボタンを押したときに表示されます。
onOptionsItemSelected メソッドは、メニューから生成されたイベントのハンドリングを行います。
ステップ 7
Notepadv1.javaの継承をActivityからListActivityに変更します。
public class Notepadv1 extends ListActivity {
変更後、Ctrl+Shift+oを押し、クラスのインポートを補完します。
ステップ 8
onCreate メソッドのコーディングに入ります。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.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class Notepadv1 extends ListActivity {
private int mNoteNumber = 1;
private NotesDbAdapter mDbHelper;
/** 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) {
// TODO Auto-generated method stub
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
return super.onOptionsItemSelected(item);
}
}
onCreate メソッドでは引数として受けたsavedInstanceStateを引数として継承元のListActivityのonCreate メソッドを呼びます。その後、setContentView メソッドを使用し、ビューを追加しています。
そして、NotesDbAdapterのインスタンスを作成し、データベースを開いています。
最後の fillData メソッドはこの時点では未定義のメソッドです。
関連記事
0 件のコメント:
コメントを投稿