我在我的应用程序中有一个为微调器定制的 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);
有用。
有人可以解释一下两种不同的方法签名之间的区别吗?