2011-08-10 5 views
0

Comment puis-je ré-instancier un ViewPager? Mon adaptateur ressemble à ceci:re instancier un PagerAdapter

private class MyPagerAdapter extends PagerAdapter{ 
    @Override 
    public int getCount() { 
      return NUM_AWESOME_VIEWS; 
    } 

    @Override 
    public Object instantiateItem(View collection, int position) { 
     LayoutInflater inflater = (LayoutInflater)cxt.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     View layout = inflater.inflate(R.layout.search_result, null); 
     // 
     TextView title = (TextView)layout.findViewById(R.id.search_result_title); 
     TextView body = (TextView)layout.findViewById(R.id.search_result_body); 
     TextView byline = (TextView)layout.findViewById(R.id.search_result_byline); 
     TextView day = (TextView)layout.findViewById(R.id.search_result_date_day); 
     TextView month = (TextView)layout.findViewById(R.id.search_result_date_month); 
     TextView year = (TextView)layout.findViewById(R.id.search_result_date_year); 
     TextView page = (TextView)layout.findViewById(R.id.search_result_page); 
     TextView page_max = (TextView)layout.findViewById(R.id.search_result_page_max); 
     // 
     title.setText(list_title.get(position).toString()); 
     body.setText(list_body.get(position).toString()); 
     day.setText(list_day.get(position).toString()); 
     month.setText(list_month.get(position).toString()); 
     year.setText(list_year.get(position).toString()); 
     byline.setText(list_byline.get(position).toString()); 
     page.setText(Integer.toString(position+1)); 
     page_max.setText(Integer.toString(NUM_AWESOME_VIEWS)); 
     // 
     ((ViewPager) collection).addView(layout,0); 
     return layout; 
    } 

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



    @Override 
    public boolean isViewFromObject(View view, Object object) { 
      return view==((View)object); 
    } 

    @Override 
    public void finishUpdate(View arg0) {} 


    @Override 
    public void restoreState(Parcelable arg0, ClassLoader arg1) {} 

    @Override 
    public Parcelable saveState() { 
      return null; 
    } 

    @Override 
    public void startUpdate(View arg0) {} 

} 

J'ai trouvé un moyen de recharger un tas de données dans la liste, mais comment puis-je recharger toutes les pages du onPostExecute (AsyncTask).

Répondre

0

Je pense qu'appeler notifyDataSetChanged(); L'utilisation de la référence de l'adaptateur résoudra vos problèmes.

+0

où dois-je appeler? après l'exécution d'Asynctask? – Tsunaze

+0

sur l'onPostExecute de votre asyncTask. Après avoir chargé tout ce que vous voulez changer dans votre liste. –

+0

le truc marche mais c'est bizarre car j'ai besoin de changer de page et de revenir voir mes nouvelles pages. – Tsunaze

3

Ajouter suivante à votre classe MyPagerAdapter:

@Override 
public int getItemPosition(Object object) { 
    return POSITION_NONE; 
} 

et appellent

myPager.getAdapter().notifyDataSetChanged(); 

de onPostExecute de votre AsyncTask