1
我試圖從擴展PagerAdapter的類中xml資源中獲取一個字符串數組。我嘗試過各種構造函數,但沒有運氣。即NullPointerExceptions任何幫助? 這是我的適配器:在PagerAdapter中獲取資源
class CharacterViewPagerAdapter extends PagerAdapter {
CharacterView activity;
public Object mPagerAdapter(Context context) {
Resources res = context.getResources();
CONTENT = res.getStringArray(R.array.heroes);
return CONTENT;
}
public int getCount() {
return CONTENT.length;
}
public CharacterViewPagerAdapter(CharacterView activity) {
this.activity = activity;
}
public Object instantiateItem(final View collection, int position) {
LayoutInflater inflater = (LayoutInflater) collection.getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
int resId = R.layout.character_profile;
View view = inflater.inflate(resId, null);
((ViewPager) collection).addView(view, 0);
activity.initPagerView(position, view);
return view;
}
@Override
public void destroyItem(View arg0, int arg1, Object arg2) {
((ViewPager) arg0).removeView((View) arg2);
}
@Override
public boolean isViewFromObject(View arg0, Object arg1) {
return arg0 == ((View) arg1);
}
@Override
public Parcelable saveState() {
return null;
}
@Override
public CharSequence getPageTitle(int position) {
return CharacterViewPagerAdapter.CONTENT[position % CONTENT.length];
}
}
CONTENT變量仍爲空。我需要幫助初始化它
分享一些代碼。開發人員瞭解並解決您的問題。 –
我已經添加了代碼。 –
Hello Innen Tensai,您的CONTENT在哪裏申報? –