2016-04-10 6 views
1

私はAutoCompleteTextViewを持っていて、フィルタを設定したいと思っています。タイプすると、テキストフィールドに1文字しか入力できません。私がコードからtextView.setFiltersを取り除くとうまくいきます。私はちょうどフィルターを持っていません。私はまた、android:textAllCaps="true"私のXMLファイルで試して、それは動作しません。どんな助けも素晴らしいだろう、ありがとう。AutoCompleteTextViewフィルタが正しく機能しない

マイコード:@のpskinkのポストの助けを借りて

AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.textfield); 
    String[] MyArray = getResources().getStringArray(R.array.myarray); 
    ArrayAdapter<String> adapter = 
      new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, MyArray); 
    textView.setFilters(new InputFilter[]{new InputFilter.AllCaps(), new InputFilter.LengthFilter(40)}); 
    textView.setAdapter(adapter); 

のXml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".myactivity"> 

    <AutoCompleteTextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/textfield" 
     android:hint="Search..."/> 

    <Button 
     android:id="@+id/btn" 
     android:onClick="buttonClickHandler" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="Do something" 
     android:layout_toRightOf="@+id/textfield"/> 
</RelativeLayout> 
+0

それを考え出した、あなたのxmlを投稿しすぎ –

+0

@VivekMishraはにこれを追加しました質問 – Greg432

+0

これはあなたの犯人の 'new InputFilter.AllCaps()'だと思います。私が理解していることは、このフィルタでは小文字を入力できないということです。あなたのtextviewに帽子の文字を入力してみてください –

答えて

0

私は

AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.textfield); 
String[] MyArray = getResources().getStringArray(R.array.myarray); 
ArrayAdapter<String> adapter = 
     new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, MyArray); 
     textView.setThreshold(1); 
     InputFilter[] filters = { 
      new InputFilter.AllCaps(), 
      new InputFilter.LengthFilter(40),}; 
    textView.setFilters(filters); 
textView.setAdapter(adapter); 
関連する問題