質問

私は作成しました AutoCompleteTextView コースのタイトルのリスト(SQLite DBから取得)と私がやりたいことを検索することは、ユーザーがドロップダウンメニューからタイトルをクリックすると、データベースからの情報全体がテキストに表示されます。下に作成されたビュー AutoCompleteTextView.

特にAndroidにとっては、プログラミングはかなり初めてです。誰かが私に正確に使用する方法を説明できれば本当に感謝しています setOnItemClickListener のデータベースのインスタンスを呼び出すには TextView 下。

レイアウトのコード(r.layout.main_courses)はです

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:padding="5dp">
<AutoCompleteTextView 
 android:id="@+id/autocomplete_course"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:hint="Search for a course"/>
<TextView
 android:id="@+id/text"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/autocomplete_course"
    android:hint="Information about the course will appear here" />
</RelativeLayout>

そして、私がこれまでに書いたAutoCompleTeTextViewのコードは次のとおりです。

protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.main_courses);
    DataBase db = new DataBase(this.getApplicationContext());
 db.openDataBase();
 ArrayList<String> aCourses = db.getCoursesArr();
 db.close();


 AutoCompleteTextView search = (AutoCompleteTextView) findViewById(R.id.autocomplete_course);
 ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.list_courses, aCourses);
 search.setAdapter(adapter);
}
役に立ちましたか?

解決

まず、aを使用してみてください CursorAdapter それから配列を取得する代わりに。小切手 このリンク 詳細については。

方法があります AutoCompleteTextView これにより、ドロップダウンが表示される前にユーザーが入力する必要がある文字の数を決定できます。 setthreshold. 。問題は、> = 1値のみを許可することです。

チェックする場合 このクラスSRCコード, 、良いニュースは、によって設定された変数が setThreshold() この方法でのみ使用されます。

public boolean enoughToFilter() {
  return getText().length() >= mThreshold;
}

ですから、私が最初に試してみることは拡張です AutoCompleteTextView そして、その方法をオーバーライドして、常に真で返すようにします。

ノート: これは将来変化し、壊れる可能性があることに留意してください。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top