question: when I click to launch pagerActivity from list, the collection built by pagerActivity is empty, and as the viewPager startup page increases, the collection increases one by one. The question is how do I realize that when I click on a location in list, the location that getItem gets (this location has not been loaded before) position is that location, not loaded by default? Thank you!
/ / pagerActivity
public void onCreate (Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detailed_pager);
mViewPager=(ViewPager)findViewById(R.id.activity_word_detailed_view_pager);
final String word=(String)getIntent().getSerializableExtra(EXTRA_WORD);
Log.d(TAG,"Word:"+word);
FragmentManager fragmentManager=getSupportFragmentManager();
mViewPager.setAdapter(new FragmentStatePagerAdapter(fragmentManager) {
@Override
public Fragment getItem(int position) {
Log.d(TAG," getItem ****"+position);
return WordDetailedFragment.newInstance(position);
}
/*
0.1 position0.1
viewpager list
setCurrentItem
*/
@Override
public int getCount() {
Log.d(TAG,"getCount ***");
return 1530;
}
});
mWordInfos=WordDetailedFragment.getWordInfos();
for (int i=0;i<mWordInfos.size();iPP)
{
if (mWordInfos.get(i).getWord().equals(word))
{
Log.d(TAG," setCurrentItem i :" +i);
Log.d(TAG,"mWordInfos.get(i).getIndex() === "+mWordInfos.get(i).getIndex());
mViewPager.setCurrentItem(mWordInfos.get(i).getIndex());
break;
}
}
}
/ / fragment of viewPager
@ Override
public void onCreate(@Nullable Bundle savedInstanceState) {
position=(int)getArguments().getSerializable(ARG_WORD);
mWordItemInfos=VocabularyListFragment.getWordItemInfos();
word=mWordItemInfos.get(position).getWord();
Log.d(TAG,"getItem position :"+position+": "+word);
sUrl=sUri.buildUpon()
.appendQueryParameter("w",word)
.build().toString();
new VocabularyItemTask().execute();
super.onCreate(savedInstanceState);
}
public static Fragment newInstance(int positon)
{
Bundle args=new Bundle();
args.putSerializable(ARG_WORD,positon);
WordDetailedFragment wordDetailedFragment=new WordDetailedFragment();
wordDetailedFragment.setArguments(args);
return wordDetailedFragment;
}
* read the log myself. The problem only lies in the position sent from getItem, which is loaded by default.