我陷入了与在 jakewharton 的 Android-ViewPagerIndicator... github 上的示例中给出的 viewpager 样式选项卡中的片段一起使用的 listview 的问题。
我为三个选项卡使用相同的库,每个选项卡都有一个列表视图,其中设置了相同的 arraylist 适配器。
我正在使用 3 个这种片段,它们都工作正常,但是当我对其中任何一个片段进行更改时,我希望我的列表在所有其他片段中更新,它并没有反映这些更改。我想如果我在三个选项卡中的任何一个列表中选中了一个复选框(我正在更新 db 和我的数组列表中的值),它们各自片段中的其他两个列表视图应该反映更改,请帮助我。请帮助我,任何帮助将不胜感激
class RingFragment extends Fragment
{
public static RingFragment newInstance(Context c, ArrayList<Ringtones> ringList)
{
RingFragment fragment = new RingFragment();
cCntxt = c;
return fragment;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle
savedInstanceState)
{
rngAdapter = new RingAdapter(cCntxt, ringFragList);
lstRingtones = new ListView(cCntxt);
lstRingtones.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));
lstRingtones.setAdapter(rngAdapter);
LinearLayout layout = new LinearLayout(getActivity());
layout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));
layout.setGravity(Gravity.CENTER);
layout.addView(lstRingtones);
return layout;
}
public class RingAdapter extends BaseAdapter
{
ArrayList<Ringtones> arlstRingAdpter;
Context adptrContext;
public boolean noRing = false;
public RingAdapter(Context c, ArrayList<Ringtones> adptrRngtones)
{
arlstRingAdpter = adptrRngtones;
adptrContext = c;
}
@Override
public int getCount()
{
return arlstRingAdpter.size();
}
@Override
public Object getItem(int position)
{
return position;
}
@Override
public long getItemId(int position)
{
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
View view = convertView;
final Wrapper wrapper;
if (view == null)
{
view = (RelativeLayout)LayoutInflater.from(cCntxt).inflate(R.layout.cell_ringtone,
null);
wrapper = new Wrapper(view);
view.setTag(wrapper);
}
else
{
wrapper = (Wrapper) view.getTag();
}
return view;
}
}
}
}
:->我调用这些片段的主要活动是
public class MainActivity extends FragmentActivity
{
ViewPager mPager;
PageIndicator mIndicator;
MusicAdapter mAdapter;
RingtonesBL rngBL;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mAdapter = new MusicAdapter(getSupportFragmentManager());
mPager = (ViewPager)findViewById(R.id.pager);
mPager.setAdapter(mAdapter);
mIndicator = (TabPageIndicator)findViewById(R.id.indicator);
mIndicator.setViewPager(mPager);
}
class MusicAdapter extends RingtoneFragmentAdapter
{
public MusicAdapter(FragmentManager fm)
{
super(fm);
}
@Override
public Fragment getItem(int position)
{
if(position % CONTENT.length == 0)
{
return
RingFragment.newInstance(AppConstants.cAppContext,AppConstants.arlst_RingAll);
}
else if(position % CONTENT.length == 1)
{
return RingFragment1.newInstance(AppConstants.cAppContext,
AppConstants.arlst_RingCart);
}
else
{
return RingFragment2.newInstance(AppConstants.cAppContext,
AppConstants.arlst_RingPurchased);
}
}
public int getItemPosition(Object object)
{
return POSITION_NONE;
}
@Override
public int getCount()
{
return CONTENT.length;
}
@Override
public CharSequence getPageTitle(int position)
{
return CONTENT[position % CONTENT.length].toUpperCase();
}
}
}
activity_main.xml 只有
<com.ringtone.TabPageIndicator
android:id="@+id/indicator"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
/>
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/indicator"
>
</android.support.v4.view.ViewPager>
请告诉我如何在更改任何一个片段时通知其他片段列表视图。