Instead of doing
convertView = infalInflater.inflate(R.layout.list_item, null);
do
convertView = infalInflater.inflate(R.layout.list_item, parent, false);
It will inflate it with the given parent, but won’t attach it to the parent.
为Fragment添加主题:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final Context contextThemeWrapper = new ContextThemeWrapper(getActivity(), R.style.Theme_PageIndicatorDefaults);
LayoutInflater localInflater = inflater.cloneInContext(contextThemeWrapper);
rootView = localInflater.inflate(R.layout.fragment_packet, null);
rootView.findViewById(R.id.btn_operate).setOnClickListener(this);
initFrame();
return rootView;
}