잡지 전자 리더기 응용 프로그램에서 기본 탐색 요소로 사용하는 뷰 페이지가 있습니다. 나는 각 기사의 "커버 페이지"로 부풀려 질 레이아웃을 정의했으며, 이것들은 잘 보여주고있다. 그러나 매 6 회의 조회수마다 광고를 표시하기 위해 다른 레이아웃을 부 풀리고 싶습니다. 그래서 viewpager 어댑터의 instantiateItem 메소드에서 다음 문장을 가지고 있습니다 : if ((position != 0) && (position%6 == 0) && (adsShown < ads.size()))
. 프로그램이 잘 실행되고 기사보기가 적절하게 팽창됩니다. 그러나 광고를 표시해야하는 위치에 도달하면보기가 비어 있습니다. 왜 이런거야? 여기 내 뷰 페이지가 빈보기를 반환하는 이유는 무엇입니까?
@Override
public Object instantiateItem(View arg0, int position) {
if ((position != 0) && (position%2 == 0) && (adsShown < ads.size())){
View v = getLayoutInflater().inflate(R.layout.adview, null);
ImageView adImg = (ImageView)v.findViewById(R.id.adImage);
adImg.setImageBitmap(ads.get(adsShown).image);
v.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent();
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(ads.get(adsShown).linkURL));
startActivity(browserIntent);
}
});
adsShown++;
System.out.println("ADSSHOWN" + adsShown);
return v;
}
else{
Article s = toShow.get(position-adsShown);
View v = getLayoutInflater().inflate(R.layout.previewpage, null);
TextView hl = (TextView)v.findViewById(R.id.coverHl);
ImageView img = (ImageView)v.findViewById(R.id.coverImg);
TextView blurb = (TextView)v.findViewById(R.id.coverBlurb);
TextView author = (TextView)v.findViewById(R.id.coverAuthor);
TextView bot = (TextView)v.findViewById(R.id.coverBot);
hl.setText(s.title);
img.setImageBitmap(s.image);
blurb.setText(Html.fromHtml(s.excerpt));
author.setText("by "+ s.author.name);
bot.setText(s.cats.get(0).name + " // " + s.date);
v.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent();
Article topass = showing;
// System.out.println("XXYYZZAA: " + topass.headline);
intent.setClassName("com.calib.caliber", "com.calib.caliber.ArticleView");
// intent.putExtra("title", topass.title);
intent.putExtra("a", topass);
// intent.putExtra("author", topass.author.name);
// intent.putExtra("content", topass.content);
// intent.putExtra("id", topass.ID);
startActivityForResult(intent, 1);
}
});
((ViewPager) arg0).addView(v);
return v;
}
}
을하고 여기에서 AdView 활동에 대한 XML 레이아웃 파일이다 : 나는 당신이에서 ((ViewPager) arg0).addView(v);
를 잊었 생각
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000">
<TextView
android:id = "@+id/adText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text = "advertisement"
android:textColor="#FFFFFF"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"></TextView>
<ImageView
android:id = "@+id/adImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below = "@id/adText">
</ImageView>
</RelativeLayout>
죄송합니다. 지적 해 주셔서 감사합니다. – drewmoore