のgetDropDownViewメソッドをオーバーライドすると、奇妙な動作が発生しますArrayAdapter
。カスタム オブジェクトから正しい文字列値を表示するには、このメソッドをオーバーライドする必要があります。それは私のアレイアダプターがどのように見えるかです:
ArrayAdapter<NoteType> adapter = new ArrayAdapter<NoteType>(this, android.R.layout.simple_spinner_item, lstNoteTypes){
@Override
public View getView(int position, View convertView, ViewGroup parent) {
TextView lbl = (TextView) super.getView(position, convertView, parent);
lbl.setText(getItem(position).getName());
return lbl;
}
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
TextView lbl = (TextView) super.getView(position, convertView, parent);
lbl.setText(getItem(position).getName());
return lbl;
}
};
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
したがって、オーバーライドするgetDropDownView
と、スピナーは次のようになります。アイテムの高さのサイズが非常に小さく、これは私が望むものではありません:
しかし、メソッドにコメントを付ける (またはオーバーライドしない)getDropDownView
と、デフォルトのスタイリングでは問題ないように見えますが、必要なテキスト値をドロップダウン項目に挿入することはできません。
をオーバーライドしたため、両方の画像のアイテムの高さに注意してくださいgetDropDownView
。
助言がありますか?または、コードに何が欠けていますか?