任何人都可以帮我解决这个问题。我想创建一个列表视图,并且在每一行中都会有一个viewpager,其适配器将为FragmentStatePageApapter,因为我想在viewpager中替换片段。
我已经使用listview和viewpager做了这个,但只有第一行会有片段和viewpager。片段不接受其他行。我不知道这是什么问题。
查看寻呼机代码:
private class MyPagerAdapter extends FragmentPagerAdapter {
SparseArray<Fragment> registeredFragments = new SparseArray<Fragment>();
public MyPagerAdapter(FragmentManager fm) {
super(fm);
System.out.println("value with in loop=============1::");
}
@Override
public Fragment getItem(int pos) {
switch(pos) {
case 0:
System.out.println("value with in loop=============2:");
FirstFragment f = new FirstFragment();
Bundle b = new Bundle();
b.putString("msg", "Instance0");
f.setArguments(b);
return f;
case 1:
System.out.println("value with in loop=============2:");
SecondFragment f2 = new SecondFragment();
Bundle b2 = new Bundle();
b2.putString("msg", "Instance1");
f2.setArguments(b2);
return f2;
case 2: return ThirdFragment.newInstance("ThirdFragment, Instance 1");
case 3: return ThirdFragment.newInstance("ThirdFragment, Instance 2");
case 4: return ThirdFragment.newInstance("ThirdFragment, Instance 3");
default: return ThirdFragment.newInstance("ThirdFragment, Default");
}
}
@Override
public int getCount() {
return 5;
}
}
&#13;
ListViewCode:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView == null) {
LayoutInflater inflater = LayoutInflater.from(getContext());
convertView = inflater.inflate(com.andtinder.R.layout.std_card_inner, parent, false);
assert convertView != null;
}
ViewPager pager = (ViewPager) convertView.findViewById(R.id.viewPager);
MyPagerAdapter adapter1=new MyPagerAdapter(getSupportFragmentManager());
pager.setAdapter(adapter1);
}
&#13;