我正在尝试刷新我在SherlockFragment中的Gridview图像。
我写了一个接口来更新适配器。但是当我尝试使用自定义覆盖接口(onCardTypeSelected)方法调用它时,所有视图都抛出NullPointerException。
我最好的尝试了我的水平。无法找到解决方案。需要一些帮助 以下是我的代码段。
public class PhotosFragment extends SherlockFragment implements CardSelectionInterface {
private Integer[] mThumbIds = {
R.drawable.thumb_card1,
R.drawable.thumb_card2,
R.drawable.thumb_card3,
R.drawable.thumb_card4
};
View view;
GridView gridView;
String[] cardTypes;
Context context;
public static PhotoImageAdapter photoImageAdapter;
@Override
public View onCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
view = inflater.inflate(R.layout.photos_layout,container,false);
gridView = (GridView) view.findViewById(R.id.photogridview);
context = view.getContext();
photoImageAdapter = new PhotoImageAdapter(context, mThumbIds);
gridView.setAdapter(photoImageAdapter); // uses the view to get the context instead of getActivity().
cardTypes = getResources().getStringArray(R.array.card_types);
gridView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int position, long arg3) {
System.out.println("*** Clicked : " + position);
}
});
System.out.println("Returning view");
return view;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
System.out.println("On Activity created");
}
@Override
public void onPause() {
super.onPause();
}
@Override
public void onCardTypeSelected(TypedArray typedArrayImages) {
mThumbIds = new Integer[typedArrayImages.length()];
for (int i = 0; i < typedArrayImages.length(); i++)
mThumbIds[i] = typedArrayImages.getResourceId(i, -1);
this.photoImageAdapter.notifyDataSetChanged();
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
System.out.println("OnAttach");
}
}