同志们请帮助。
我创建了ViewPager,它显示一个空白屏幕。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_textgrid);
viewPager = (ViewPager) findViewById(R.id.textpager);
items = new ArrayList<RssItem>();
LoadText loader = new LoadText();
loader.execute();
}
private class LoadText extends AsyncTask<Void, Void, ArrayList<RssItem>> {
@Override
protected void onPostExecute(ArrayList<RssItem> result) {
Log.i(LOG_TAG, "LOADED:" + result.size());
Log.i(LOG_TAG, "CUUR_ITEM:" + viewPager.getCurrentItem());
pd.dismiss();
items.addAll(result);
adapter = new TextAdapter(TextActivity.this, items);
viewPager.setAdapter(adapter);
adapter.notifyDataSetChanged();
if (items.size() > 0) {
viewPager.setCurrentItem(1);
Log.i(LOG_TAG, "CUR_ITEM:" + viewPager.getCurrentItem());
}
super.onPostExecute(result);
}
}
public class TextAdapter extends PagerAdapter {
private Activity _activity;
private ArrayList<RssItem> items;
@Override
public int getCount() {
return items.size();
}
public TextAdapter(Activity activity, ArrayList<RssItem> items) {
this._activity = activity;
this.items = items;
}
private RssItem getItem(int pos) {
return this.items.get(pos);
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == ((RelativeLayout) object);
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
LayoutInflater inflater = (LayoutInflater) _activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View viewLayout = inflater.inflate(R.layout.activity_text, container,
false);
RssItem item = getItem(position);
TextView title = (TextView) viewLayout.findViewById(R.id.textTitle);
TextView rating = (TextView) viewLayout.findViewById(R.id.textRating);
TextView author = (TextView) viewLayout.findViewById(R.id.textAuthor);
TextView content = (TextView) viewLayout.findViewById(R.id.textContent);
content.setText(item.getContent());
title.setText(item.getTitle());
rating.setText(item.getRating());
author.setText(item.getAuthor());
content.setText(item.getContent());
return viewLayout;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
((ViewPager) container).removeView((RelativeLayout) object);
}
}
日志显示上传了大量数据。
如果您更改程序页面,它会更改(在日志中可以看到)。
空白屏=(
答案 0 :(得分:0)
尝试使用:
viewPager.offscreenPageLimit = adapter.count