0

i have a fragment activity that have 4 page and load from 4 link from internet when program start customlist show lists but when i change page the view show white page

my fragment :

public class VpiAbsTestActivitynouser extends SherlockFragmentActivity {


private static final String[] CONTENT = new String[] {" page1","page2","page3","page4"};

TestFragmentAdapter mAdapter;
 ViewPager mPager;
    PageIndicator mIndicator;
    TextView mSearchView;


    public String[] xmlURLArray = new String[]{"link1.xml","link2.xml","link3.xml","link4.xml"};


protected void onCreate(Bundle savedInstanceState) {
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.simple_tabs);

    Intent i = new Intent(this, transparentone.class);
    startActivity(i);

    mAdapter = new TestFragmentAdapter(getSupportFragmentManager());
    mPager = (ViewPager)findViewById(R.id.pager);
    mPager.setAdapter(mAdapter);
    mIndicator = (TabPageIndicator)findViewById(R.id.indicator);
    mIndicator.setViewPager(mPager);
    mIndicator.setCurrentItem(1);


}


class TestFragmentAdapter extends FragmentPagerAdapter {        
    private int mCount = CONTENT.length;

    public TestFragmentAdapter(FragmentManager fm) {
        super(fm);

    }

    @Override
    public Fragment getItem(int position) {
            Bundle args = new Bundle();
            args.putString("url", xmlURLArray[position]);

        return  customlist.newInstance(args);

    }



    @Override
    public int getCount() {
        return mCount;
    }


    public CharSequence getPageTitle(int position) {
        return VpiAbsTestActivitynouser.CONTENT[position % VpiAbsTestActivitynouser.CONTENT.length].toUpperCase();
    }

     @Override
        public void destroyItem(View collection, int position, Object view) {
             ((ViewPager) collection).removeView((View) view);

        }



 }

}

and my custom list code is :

public class customlist extends SherlockFragment  {
int fragment_position_in_viewpager = 0;

// All static variables

 public static customlist newInstance(Bundle args) {
        customlist fragment = new customlist();
        fragment.setArguments(args);
        return fragment;
        }

ListView list;
LazyAdapterbeth adapter1;



public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);


        }


public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (getArguments() != null) { 
        URL = getArguments().getString("url"); 
        } 
        new getFeed().execute(); 
} 

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
     ViewGroup root = (ViewGroup) inflater.inflate(
                R.layout.dovomi, container, false);



        return root;
    }

public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    if (getArguments() != null) {
        fragment_position_in_viewpager = getArguments().getInt("position");
        //Update the Fragment on ViewPager Position.
    }


}


private class getFeed extends AsyncTask<Void, Void, Document> {

       @Override
       protected void onPreExecute() { 
       }

    protected Document doInBackground(Void... params) {
    }

    protected void onPostExecute(Document doc) {
    }



    list=(ListView)getView().findViewById(R.id.list);
    adapter1=new LazyAdapterbeth(getActivity(), songsList);
    adapter1.notifyDataSetChanged();
    list.setAdapter(adapter1);

how i can refresh view when change the view from page 1 to page 2 ?

1 Answer 1

0

As your code is very long, I didn't analyse it deeply but the following solutions come to my mind:

1) onCreateView for each fragment method is regularly called when fragment is recreated/its view hierarchy is recreated

Thus it can be one place for refreshing. However onCreateView is called slightly earlier than before paging displaying (usually where you display page nr 2, onCreateView for page number 3 is executed). The best idea is to put a short code displaying Toast in onCreateView and then you will know if it's ok for you.

2) Your main activity (extending FragmentActivity) can get 3 methods which are executed when swiping between fragments. It will look more or less in the following way:

public MyActivity extends FragmentActivity implements OnPageChangeListener {

@Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
         mainActivityPageAdapter = new MainActivityPageAdapter (this, getSupportFragmentManager());
        mainActivityViewPager = (ViewPager) findViewById(R.id.main_activity_view_pager);
        mainActivityViewPager.setAdapter(mainActivityPageAdapter);

        //set listener (for navigator)
        mainActivityViewPager.setOnPageChangeListener(this);

}

//and now you have 3 methods
    @Override
    public void onPageScrollStateChanged(int state) {
    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {
}       

You can read more http://developer.android.com/reference/android/support/v4/view/ViewPager.OnPageChangeListener.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.