Xuni for Android のドキュメント
クイックスタート:Xuni AutoComplete へのデータの挿入

このセクションでは、XuniAutoComplete コントロールを Android アプリケーションに追加し、そのコントロールにデータを挿入する方法を説明します。このトピックは 3 つの手順で構成されます。

次の図は、ユーザーがテキストを入力したときに、XuniAutoComplete コントロールがドロップダウンリストに候補リストをどのように提供するかを示しています。

Xuni AutoComplete control

手順 1:定義済み候補リストの作成

  1. Eclipse で新しい Android アプリケーションを作成します(詳細については「Eclipse での新しい Android アプリの作成」を参照)。
  2. プロジェクトに新しいクラスを追加し、たとえば「DropDownItem」と名前を付けます。
  3. DropDownItem クラスに次のコードを追加して、定義済み候補のリストを作成します。
    Java
    コードのコピー
    public class DropDownItem 
    {
          public String name;
          public String value;
          static String[] country = { "アフガニスタン", "中国", "インド", "日本", "ネパール", "北朝鮮", "パキスタン", "韓国", "スリランカ" };
            
          DropDownItem(String name, String value)
             {
                this.name = name;
                this.value = value;
             }
    
          static ObservableList<DropDownItem> getList()
             {
                ObservableList<DropDownItem> list = new ObservableList<DropDownItem>();
                for (int i = 0; i < country.length; i++)
                    {
                        list.add(new DropDownItem(country[i], i + ""));
                     }
                    
                    return list;
             }
    }
    

手順 2:XuniAutoComplete コントロールの追加と候補の挿入

  1. プロジェクトの MainActivity クラスに、次の Xuni 参照を追加します。
    Java
    コードのコピー
    import com.grapecity.xuni.core.ObservableList;
    import com.grapecity.xuni.input.autocomplete.MatchType;
    import com.grapecity.xuni.input.autocomplete.XuniAutoCompleteTextView;
    
  2. activity_main ファイルに次のコードを追加して、レイアウトに入力フィールドを設定します。
    XML
    コードのコピー
    <GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:columnCount="2"
        android:paddingBottom="20dp"
        android:paddingLeft="20dp"
        android:paddingRight="20dp"
        android:paddingTop="20dp"
        android:rowCount="4" >
    
        <com.grapecity.xuni.input.autocomplete.XuniAutoCompleteTextView
            android:id="@+id/autocomplete_highlight"
            android:layout_width="300dp"
            android:layout_height="wrap_content">      
        </com.grapecity.xuni.input.autocomplete.XuniAutoCompleteTextView>
    
    </GridLayout>
    
  3. XuniAutoComplete コントロールをインスタンス化し、コードに示すように setItemsSource プロパティを設定して、コントロールを DropDownItem クラスに連結します。
    Java
    コードのコピー
    public class MainActivity extends Activity 
    {
        ObservableList<DropDownItem> dataSource;
        @Override
        protected void onCreate(Bundle savedInstanceState) 
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            XuniAutoCompleteTextView highLightAutoComplete = (XuniAutoCompleteTextView) this.findViewById(R.id.autocomplete_highlight);
            highLightAutoComplete.setItemsSource(DropDownItem.country);
            highLightAutoComplete.setMatchType(MatchType.CONTAINS);
            highLightAutoComplete.setThreshold(1);
        }
    }
    

手順 3:プロジェクトの実行

パッケージエクスプローラーで、アプリケーションを右クリックし、[実行]→[Android アプリケーション]を選択します。

 

 


Copyright © GrapeCity inc. All rights reserved.