在下面的代码中(为清楚起见而缩短),当我旋转设备时,适配器变量接收空值,而 gridView 变量接收空值。
旋转设备屏幕后,谁能帮我保留适配器和gridView?
感谢。
(抱歉英语不好)
public class FlickrXmlFragment extends Fragment {
private GridView gridView;
private FlickrGridViewAdapter adapter;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
//...
View view = darkInflater.inflate(R.layout.fragment_flickr_xml,
container, false);
//...
gridView = (GridView) view.findViewById(R.id.flickr_gridView);
return view;
}
class FlickrPhotoSearchThread extends
AsyncTask<String, Void, List<FlickrImagem>> {
@Override
protected void onPreExecute() { //... process... }
@Override
protected List<FlickrImagem> doInBackground(String... params) { //process... }
@Override
protected void onPostExecute(List<FlickrImagem> result) {
//...
adapter = new FlickrGridViewAdapter(getActivity(), 0, result);
gridView.setAdapter(adapter);
adapter.notifyDataSetChanged();
//...
}
}
}