2010-12-12 11 views
2

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

私はかなりプログラミングの新人です、特にアンドロイドのために、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); 
} 

答えて

3

あなたがすべきまず第一に配列を取得する代わりにCursorAdapterを使用してみてください。詳細については、this linkを確認してください。

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

あなたがthis class src codeをチェックする場合は、良いニュースは、setThreshold()によって設定された変数は、この方法でのみ使用されていることである。

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

だから私がしようと最初にすることはAutoCompleteTextViewを拡張し、常にリターンにそのメソッドをオーバーライドしています本当。

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

関連する問題