AndroidDevelopersのチュートリアルのAuto Completeを実行します。
※その2は「Auto Completeチュートリアル」の最後までコードを実行します。
【手順】
1.「Androidプロジェクトの作成方法」の手順で、「AndroidSample022-HelloAutoComplete2」といプロジェクトを作成。
※プロジェクトの設定は以下の通り。
2.「任意のファイルの作成方法」の手順で、「res/layout/」ディレクトリに「list_item.xml」というファイルを作成。
3.「list_item.xml」を以下の様に入力。
4.「Ctrl+Shift+F」を押し、ソースコードをフォーマッティング。
5.「res/layout/main.xml」を以下の様に入力。
6.「Ctrl+Shift+F」を押し、ソースコードをフォーマッティング。
7.「res/values/strings.xml」を以下の様に入力。
8.「Ctrl+Shift+F」を押し、ソースコードをフォーマッティング。
9.「HelloAutoComplete.java」を以下の様に入力。
11.「Androidプロジェクトの実行方法」の手順で、「Androidプロジェクト」を実行。
12.エミュレータが起動しロックを解除し、以下の様にアプリケーションが実行されれば成功です。
以上です。
3.「list_item.xml」を以下の様に入力。
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:textColor="#000"
android:textSize="16sp" >
</TextView>
4.「Ctrl+Shift+F」を押し、ソースコードをフォーマッティング。
5.「res/layout/main.xml」を以下の様に入力。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Country" />
<AutoCompleteTextView
android:id="@+id/autocomplete_country"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp" />
</LinearLayout>
6.「Ctrl+Shift+F」を押し、ソースコードをフォーマッティング。
7.「res/values/strings.xml」を以下の様に入力。
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, HelloAutoComplete2!</string>
<string name="app_name">AndroidSample022-HelloAutoComplete2</string>
<string-array name="countries_array">
<item>Bahrain</item>
<item>Bangladesh</item>
<item>Barbados</item>
<item>Belarus</item>
<item>Belgium</item>
<item>Belize</item>
<item>Benin</item>
</string-array>
</resources>
8.「Ctrl+Shift+F」を押し、ソースコードをフォーマッティング。
9.「HelloAutoComplete.java」を以下の様に入力。
package com.example.androidsample022;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
public class HelloAutoComplete2 extends Activity {
/** Called when the activity is first created. */
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.autocomplete_country);
String[] countries = getResources().getStringArray(
R.array.countries_array);
ArrayAdapter adapter = new ArrayAdapter(this,
R.layout.list_item, countries);
textView.setAdapter(adapter);
}
}
10.「Ctrl+Shift+F」を押し、ソースコードをフォーマッティング。11.「Androidプロジェクトの実行方法」の手順で、「Androidプロジェクト」を実行。
12.エミュレータが起動しロックを解除し、以下の様にアプリケーションが実行されれば成功です。
以上です。
Auto+Complete(%E3%81%9D%E3%81%AE2)-01.png)
0 件のコメント:
コメントを投稿
注: コメントを投稿できるのは、このブログのメンバーだけです。