我浏览了许多有关屏幕方向的帖子。但我的情况有点不同。我的 ListView 有自定义行布局。使用 AsyncTask 从 Internet 加载 ImageView 位图。我想要的是,是否可以保存我的 ListView 的 ArrayAdapter 或整个 ListView 以便在方向屏幕更改时保留其状态。
请建议一些帖子,或者如果发布了一些代码,它将非常有用。
public View getView(int position, View convertView, ViewGroup parent) {
final Contents entry = contentList.get(position);
View row = convertView;
LayoutInflater infltr = null;
if (row == null) {
infltr = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = inflater.inflate(R.layout.highlight_contents_layout,
parent, false);
}
ImageView imgViewImage = (ImageView) row
.findViewById(R.id.imgView_Image);
if (imgViewImage.getTag() == null) {
new DownloadImage(imgViewImage, entry).execute(); //Async Task to download Image
}
}
return row;
}
在 onCreate 我有一个函数调用来填充列表,函数调用是:
init(){
listContent = (ListView) findViewById(R.id.listview); //vairable declared at top of my class;
contentlist = new ArrayList<Contents>(); //Variable Declared at top of class;
//... Populated the contenlist... in here
//..
//..
adapter = new ListAdapter(getApplicationContext(),
R.layout._contents_layout, contentList,
thumb_image_bytes);
listContent.setAdapter(adapter);
adapter.notifyDataSetChanged();
}