public class CustomAdapter extends BaseAdapter
extend BaseAdapter代碼:
public View getView(int index, View view, final ViewGroup parent) {
if (view == null) {
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
view = inflater.inflate(R.layout.single_list_item, parent, false);
}
}
TextView textView = (TextView) view.findViewById(R.id.tv_string_data);
textView.setText(dataModel.getName());
我的問題是什麼時候view == null
?
為什麼需要代碼:if (view == null) {}
view會被復用,所以會有null和非null。