2

狂気...私が何をしようとも、私のAutoCompleteTextViewショーはデフォルトのスタイルでアイテムをドロップダウンします。ドロップダウンビューにアクセスできないようです。XMLでスタイリングし、アダプタでコーディングし、AutoCompleteTextView自体をコーディングしてみました。

spinner_dropdown_item.xml:

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
      android:paddingLeft="10dp"
      android:paddingRight="10dp"
      android:paddingTop="15dp"
      android:paddingBottom="15dp"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:textColor="#000"
      android:textSize="16dp"
    />

私のクライアント(LoginFragment.java):

AutoCompleteTextView user_name = (AutoCompleteTextView) layout.findViewById(R.id.user_name);

final MyAdapter<User> adapter = new MyAdapter<User>(my_activity, my_list);
//does nothing
adapter.setDropDownViewResource(R.layout.spinner_dropdown_item);
//crashes app with no error or anything!
user_name.setDropDownBackgroundResource(R.layout.spinner_dropdown_item);

user_name.setAdapter(user_adapter);

最後に、私のアダプターでは、スピナーのドロップダウンアイテムのスタイルを設定するために完全に機能していますが、AutoCompleteTextViewのドロップダウンのスタイルを設定できません。

@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
    TextView tv;
    if (convertView == null) {
        LayoutInflater inflater = LayoutInflater.from(context);
        tv = (TextView) inflater.inflate(R.layout.spinner_dropdown_item, null);
    } else {
        tv = (TextView) convertView;
    }
    T object = objects.get(position);
    String label = NULL_ITEM;
    if (object != null) {
        label = object.toString();
    }
    tv.setText(label);
    return tv;
}

AutoCompleteTextViewのドロップダウンリストを変更して、ドロップダウンテキストアイテムのスタイルを変更するにはどうすればよいですか?

4

1 に答える 1

1

問題を特定したようです。私のAdapterクラスは、コンストラクターで目的のレイアウトを受け取る必要がありました。アダプター自体で目的のレイアウトを参照できなかった理由はIDEAではありません

于 2013-03-26T20:13:33.680 に答える