MainFragment 类:(即使在膨胀之后,gridview 也是空的)
public class FragmentMain extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_main, container, false);
GridView gridview = (GridView)getActivity().findViewById(R.id.grid_view);
gridview.setAdapter(new ImageAdapter(getActivity(), thumbnails)); //gridview is null!!!
getActivity().setTitle(title);
return view;
}
}
fragment_main.xml 布局
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/grid_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:numColumns="auto_fit"
android:columnWidth="90dp"
android:horizontalSpacing="10dp"
android:verticalSpacing="10dp"
android:gravity="center"
android:stretchMode="columnWidth" >
</GridView>