Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

listview not refreshing in fragment with viewpager tabs

I got stuck into the problem with listview used with fragment inside viewpager styled tabs that given in jakewharton's Android-ViewPagerIndicator... example on github.

i am using the same lib for three tabs each having a list view with same arraylist set to there adapters.

I am using 3 this kind of fragment all are working fine but as i want my list to be updated in all other fragments when i make changes in any one of them, it is not reflecting the changes. i want if i checked a checkbox in any one of the list among three tabs (i am updating values in db and my arraylist) other two listview inside their respective fragments should reflect changes, please help me on this. please help me on this, any help would be appreciated

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;
}
 }  
 }
 }

:->My Main Activity from where i am calling these fragments is

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 having only

 <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>

Please tell me how can i notify the other fragments listview while changing in any one.

like image 272
skygeek Avatar asked Nov 12 '22 22:11

skygeek


1 Answers

Please try to do stuff out of this branches: for example:

else 
{
 wrapper = (Wrapper) view.getTag();
}

wrapper.txtText.setText("Refreshed");

return view;
}
like image 89
Gent Avatar answered Dec 15 '22 09:12

Gent