我有一个带有自定义适配器的列表视图的片段。通过选项卡访问片段。
当我单击 fragmentA 时,它会渲染一些图像并将它们显示在列表中。
当我单击 fragmentB 时,它会显示其他内容。
当我再次单击 fragmentA 时,它将重新渲染图像。如何保存它的状态,以避免重新渲染?
片段A:
public class FragmentA extends Fragment {
public ImageView my_img;
private static int hitcount = 0;
public Bitmap mybitmap = null;
public ProgressDialog pd;
private View myFragmentView;
public HashMap<Integer,String> urlList = new HashMap<Integer,String>();
public String inputUrl = "http://google.com/image.png";
ListView listview;
public String[] imgs = new String[20];
CustomAdapter adapter;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
myFragmentView = inflater.inflate(R.layout.fragmenta, container, false);
listview = (ListView) myFragmentView.findViewById(R.id.listView1);
if(hitcount < 1) {
urlList = ((JSONActivity)getActivity()).imageList;
for(int i = 0; i < urlList.size(); i++)
imgs[i] = (String)urlList.values().toArray()[i];
adapter = new CustomAdapter(getActivity(), imgs );
listview.setAdapter(adapter);
}
listview.setActivated(true);
hitcount++;
return myFragmentView;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
}
有任何想法吗?
提前致谢!