アプリのスピナー用にカスタマイズされた ArrayAdapter を使用しています。getDropDownView() メソッドのコードは次のとおりです。
@Override
public View getDropDownView(int position, View convertView,ViewGroup parent) {
View vista = convertView;
if (vista==null) {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
vista = inflater.inflate(R.layout.row_spinner,null);
}
TextView tv = (TextView) vista.findViewById( R.id.textview_entry );
if( !Utils.isSDKAbove( Utils.HONEY_COMB ) )
{
tv.setTextColor( getContext().getResources().getColor( android.R.color.primary_text_light ) );
}
tv.setText( getItem( position ) );
return vista;
}
tv.setText() の場合、TextView に対して NullPointerException がスローされます。
しかし、私が変更したとき
vista = inflater.inflate(R.layout.row_spinner, null);
に
vista = inflater.inflate(R.layout.row_spinner, parent, false);
できます。
メソッドの2つの異なる署名の違いについて誰かがもう少し説明できますか?