2

コース タイトルのリスト (sqlite db から取得) を検索するための を作成しましAutoCompleteTextViewた。ユーザーがドロップダウン メニューからタイトルをクリックすると、データベースから彼に関するすべての情報が取得されます。の下に作成されたテキスト ビューに選択内容が表示されますAutoCompleteTextView

私はプログラミング、特にアンドロイドのプログラミングにかなり慣れていないので、誰かが以下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);
}
4

1 に答える 1

3

まずCursorAdapter、配列を取得する代わりに、を使用してみてください。詳細については、このリンクを確認してください。

AutoCompleteTextViewドロップダウンが表示される前にユーザーが入力する必要のある文字数を決定できるメソッド、 setThresholdがあります。問題は、>=1の値しか許可されないことです。

このクラスのsrcコードを確認すると、良いニュースは、によって設定された変数setThreshold()がこのメソッドでのみ使用されることです。

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

したがって、私が最初に試みることはAutoCompleteTextView、そのメソッドを拡張してオーバーライドし、常にtrueを返すことです。

注:これは将来変更される可能性があり、破損する可能性があることに注意してください。

于 2010-12-12T13:44:26.357 に答える