gpt4 book ai didi

java - ViewPager 没有显示任何内容

转载 作者:IT老高 更新时间:2023-10-28 21:03:28 25 4
gpt4 key购买 nike

我正在使用自定义 View 寻呼机适配器创建 View 寻呼机,但是当我运行项目时,我什么也看不到

  public class CustomAdapter extends PagerAdapter {

private List<NewsObject> newsObjects;
private Activity mActivity;
private LayoutInflater inflater;
private ImageLoaderConfiguration imageConfig;
private ImageLoader imageLoader = ImageLoader.getInstance();

public CustomAdapter(List<NewsObject> newsObjects, Activity mActivity) {
super();
Log.d("Con :", "structor");
this.newsObjects = newsObjects;
this.mActivity = mActivity;
imageConfig = new ImageLoaderConfiguration.Builder(
mActivity.getApplicationContext()).build();
imageLoader.init(imageConfig);
}

@Override
public int getCount() {
return this.newsObjects.size();
}

@Override
public void destroyItem(View collection, int position, Object view) {
((ViewPager) collection).removeView((View) view);
}

@Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}

@Override
public Object instantiateItem(ViewGroup container, int position) {

ImageViewPlus img_news_image;
TextView txt_news_title;
TextView txt_news_description;

inflater = (LayoutInflater) mActivity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

View viewLayout = inflater.inflate(R.layout.detail_news_page, null);

img_news_image = (ImageViewPlus) viewLayout
.findViewById(R.id.img_detail_news_image);
txt_news_title = (TextView) viewLayout
.findViewById(R.id.txt_detail_news_title);
txt_news_description = (TextView) viewLayout
.findViewById(R.id.txt_detail_news_description);

Log.d("TAG :", "instantiateItem");

imageLoader.displayImage(newsObjects.get(position).getNews_image(),
img_news_image);

Toast.makeText(mActivity.getApplicationContext(),
Constantz.newsObjects.get(position).getNews_id() + "",
Toast.LENGTH_SHORT).show();

txt_news_title.setText(newsObjects.get(position).getNews_title());
txt_news_description.setText(newsObjects.get(position)
.getNews_description());

return viewLayout;
}

}

但是 toast 正在显示,但我在我的应用程序上看不到任何文本

最佳答案

container.addView(viewLayout);

在返回 View 之前 instantiateItem

  public Object instantiateItem(ViewGroup container, int position) {

ImageViewPlus img_news_image;
TextView txt_news_title;
TextView txt_news_description;

inflater = (LayoutInflater) mActivity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

View viewLayout = inflater.inflate(R.layout.detail_news_page, null);

img_news_image = (ImageViewPlus) viewLayout
.findViewById(R.id.img_detail_news_image);
txt_news_title = (TextView) viewLayout
.findViewById(R.id.txt_detail_news_title);
txt_news_description = (TextView) viewLayout
.findViewById(R.id.txt_detail_news_description);

Log.d("TAG :", "instantiateItem");

imageLoader.displayImage(newsObjects.get(position).getNews_image(),
img_news_image);

Toast.makeText(mActivity.getApplicationContext(),
Constantz.newsObjects.get(position).getNews_id() + "",
Toast.LENGTH_SHORT).show();

txt_news_title.setText(newsObjects.get(position).getNews_title());
txt_news_description.setText(newsObjects.get(position)
.getNews_description());
container.addView(viewLayout);

return viewLayout;
}

关于java - ViewPager 没有显示任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22345409/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com