2016-04-11 28 views
0

を働いていない私は、次のように私が実施している私のメインの活動でautocompletetextviewを持っている:Autocompletetextviewカスタムアダプタ

String[] values = new String[]{"Linux", "Ubuntu", "iPhone", "Android", "iOS"}; 
autoCompleteTextView = (AutoCompleteTextView) findViewById(R.id.autocompleteView); 
autoCompleteTextView.addTextChangedListener(this); 
autoCompleteTextView.setAdapter(new AutoCompleteAdapter(this, values)); 

私も同じクラスにTextWatcherするためのメソッドを実装しています。

マイadapterクラスは次のようになります。

<AutoCompleteTextView 
     android:id="@+id/autocompleteView" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/activity_heading_1" 
     android:completionThreshold="1" 
     android:hint="@string/autocomplete_hint" /> 

私の値はLinux, Ubuntu, iPhone, Android and iOSなので、私は私のオートコンプリートがそのようなときに動作することを期待:

public class AutoCompleteAdapter extends ArrayAdapter<String> { 

private final Context context; 
private final String[] values; 

public AutoCompleteAdapter(Context context, String[] values) { 
    super(context, -1, values); 
    this.context = context; 
    this.values = values; 
} 

@Override 
public View getView(int pos, View convertView, ViewGroup parent){ 
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    View rowView = inflater.inflate(R.layout.autocomplete_item, parent, false); 
    TextView textView1 = (TextView) rowView.findViewById(R.id.autocomplete_symbol); 
    TextView textView2 = (TextView) rowView.findViewById(R.id.autocomplete_company_name); 
    textView1.setText(values[pos]); 
    textView2.setText(values[pos]); 
    return rowView; 
} 
} 

そして、ここでは、ビューのための私のxmlコードです私はa/Aと入力し、Androidと表示されます。代わりに、常に0の要素を表示します。つまり、常にLinuxと表示されます。私がi/Iと入力すると、iPhone and iOSと表示されますが、代わりにLinux, Ubuntuと表示されます。どんな助けもありがとうございます。ありがとう!

UPDATE:私は、ドロップダウンリストから要素をクリックすると、正しい値がAndroidautocompleteに表示されます、私はそれをクリックしたときに、私は、a/Alinuxかかわらず、ドロップダウンに表示されます入力すると、viewすなわちに置き換えられますビュー。

答えて

1

あなたのArrayAdapter

チェックこのtutorialのカスタムFilterを実装する必要があります。

関連する問題