Sorry but I write wrong, the fragment class doesn't have the 
onRetainNonConfigurationInstan
ce() method!!! How I can retain my fragment in configuration change if I 
don't have this method!!
Thank you!


On Thursday, October 18, 2012 8:50:20 PM UTC+2, MagouyaWare wrote:
>
> Ummm... if you look at the documentation for the deprecated method it 
> tells you what to do...
>
> Thanks,
> Justin Anderson
> MagouyaWare Developer
> http://sites.google.com/site/magouyaware
>
>
> On Thu, Oct 18, 2012 at 9:27 AM, Giosia Gentile <[email protected]<javascript:>
> > wrote:
>
>> Ok but
>> onRetainNonConfigurationInstance()
>> is deprecated! What I must use insted of it??
>>
>> On Oct 18, 12:51 pm, Piren <[email protected]> wrote:
>> > Orientation change will be harder to handle... see this for help:
>> http://developer.android.com/guide/topics/resources/runtime-changes.html
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> > On Thursday, October 18, 2012 12:40:49 PM UTC+2, Giosia Gentile wrote:
>> >
>> > > Thank you I will try it this evening!!
>> > > Please can you help me also with the screen orientation??? I used the
>> > > setRetainIstance(true) but it donìt work!!
>> >
>> > > On Thursday, October 18, 2012 10:08:08 AM UTC+2, Piren wrote:
>> >
>> > >>
>> http://developer.android.com/reference/android/support/v4/view/ViewPa...)
>> >
>> > >> just set it to 2
>> >
>> > >> On Wednesday, October 17, 2012 7:30:54 PM UTC+2, Giosia Gentile 
>> wrote:
>> >
>> > >>> it is one week I try to solve this problem whitout success. Please
>> > >>> help me.
>> >
>> > >>> I use the tabs navigation with viewpager. This is the class where I
>> > >>> put the tabs and the FragmentPagerAdapter class:
>> > >>> public class Detail extends SherlockFragmentActivity {
>> >
>> > >>>     ViewPager  mViewPager;
>> >
>> > >>>     TabsAdapter mTabsAdapter;
>> >
>> > >>>     @Override
>> > >>>     public void onCreate(Bundle savedInstanceState) {
>> >
>> > >>>         super.onCreate(savedInstanceState);
>> >
>> > >>>         setContentView(R.layout.activity_main);
>> >
>> > >>>      ...
>> >
>> > >>>      ActionBar bar = getSupportActionBar();
>> > >>>      bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
>> > >>>      bar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);
>> >
>> > >>>      mViewPager = (ViewPager)findViewById(R.id.pager);
>> >
>> > >>>      // Add the tabs
>> > >>>      mTabsAdapter = new TabsAdapter(this, bar, mViewPager);
>> > >>>      mTabsAdapter.addTab(bar.newTab().setText(R.string.filmtab),
>> > >>>              FragmentFilm.class, null);
>> > >>>      mTabsAdapter.addTab(bar.newTab().setText(R.string.cinematab),
>> > >>>              FragmentCinema.class, null);
>> > >>>      mTabsAdapter.addTab(bar.newTab().setText(R.string.dintornitab),
>> > >>>              FragmentPdi.class, null);
>> >
>> > >>>      if (savedInstanceState != null) {
>> >
>> > >>> bar.setSelectedNavigationItem(savedInstanceState.getInt("tab"));
>> > >>>      }
>> >
>> > >>>     }
>> >
>> > >>>      @Override
>> > >>>         protected void onSaveInstanceState(Bundle outState) {
>> > >>>             super.onSaveInstanceState(outState);
>> > >>>             outState.putInt("tab",
>> > >>> getSupportActionBar().getSelectedNavigationIndex());
>> > >>>         }
>> >
>> > >>>      public static class TabsAdapter extends FragmentPagerAdapter
>> > >>>      implements ViewPager.OnPageChangeListener, 
>> ActionBar.TabListener
>> > >>> {
>> > >>>          private final Context mContext;
>> > >>>          private final ActionBar mBar;
>> > >>>          private final ViewPager mViewPager;
>> > >>>          private final ArrayList<TabInfo> mTabs = new
>> > >>> ArrayList<TabInfo>();
>> >
>> > >>>          static final class TabInfo {
>> > >>>              private final Class<?> clss;
>> > >>>              private final Bundle args;
>> >
>> > >>>              TabInfo(Class<?> _class, Bundle _args) {
>> > >>>                  clss = _class;
>> > >>>                  args = _args;
>> > >>>              }
>> > >>>          }
>> >
>> > >>>          public TabsAdapter(Detail activity, ActionBar bar, 
>> ViewPager
>> > >>> pager) {
>> > >>>              super(activity.getSupportFragmentManager());
>> > >>>              mContext = activity;
>> > >>>              mBar = bar;
>> > >>>              mViewPager = pager;
>> > >>>              mViewPager.setAdapter(this);
>> > >>>              mViewPager.setOnPageChangeListener(this);
>> > >>>          }
>> >
>> > >>>          public void addTab(ActionBar.Tab tab, Class<? extends
>> > >>> Fragment> clss, Bundle args) {
>> > >>>              TabInfo info = new TabInfo(clss, args);
>> > >>>              tab.setTag(info);
>> > >>>              tab.setTabListener(this);
>> > >>>              mTabs.add(info);
>> > >>>              mBar.addTab(tab);
>> > >>>              notifyDataSetChanged();
>> > >>>          }
>> >
>> > >>>          @Override
>> > >>>          public int getCount() {
>> > >>>              return mTabs.size();
>> > >>>          }
>> >
>> > >>>          @Override
>> > >>>          public Fragment getItem(int position) {
>> > >>>              TabInfo info = mTabs.get(position);
>> > >>>              return Fragment.instantiate(mContext,
>> > >>> info.clss.getName(), info.args);
>> > >>>          }
>> >
>> > >>>          @Override
>> > >>>          public void onPageScrolled(int position, float
>> > >>> positionOffset, int positionOffsetPixels) {
>> > >>>          }
>> >
>> > >>>          @Override
>> > >>>          public void onPageSelected(int position) {
>> > >>>              mBar.setSelectedNavigationItem(position);
>> > >>>          }
>> >
>> > >>>          @Override
>> > >>>          public void onPageScrollStateChanged(int state) {
>> > >>>          }
>> >
>> > >>>          @Override
>> > >>>          public void onTabSelected(Tab tab, FragmentTransaction ft) 
>> {
>> > >>>              Object tag = tab.getTag();
>> > >>>              for (int i=0; i<mTabs.size(); i++) {
>> > >>>                  if (mTabs.get(i) == tag) {
>> > >>>                      mViewPager.setCurrentItem(i);
>> > >>>                  }
>> > >>>              }
>> > >>>          }
>> >
>> > >>>          @Override
>> > >>>          public void onTabUnselected(Tab tab, FragmentTransaction 
>> ft)
>> > >>> {
>> >
>> > >>>          }
>> >
>> > >>>          @Override
>> > >>>          public void onTabReselected(Tab tab, FragmentTransaction 
>> ft)
>> > >>> {
>> >
>> > >>>          }
>> > >>>      }
>> > >>> }
>> >
>> > >>> The 3 fragment classes are all the same I copy here just one; In the
>> > >>> fragment class I use async task for download the data I need to put 
>> in
>> > >>> the view, I do this in the onActivityCreated method:
>> >
>> > >>> public class FragmentFilm extends SherlockFragment
>> > >>> {
>> >
>> > >>>     private Detail act;
>> >
>> > >>>     private DetailedRec detail_film;
>> > >>>     private View view;
>> > >>>     private String a;
>> >
>> > >>>     @Override
>> > >>>     public View onCreateView(LayoutInflater inflater, ViewGroup
>> > >>> container,
>> > >>>             Bundle savedInstanceState)
>> > >>>     {
>> >
>> > >>>         setRetainInstance(true);
>> > >>>         view = inflater.inflate(R.layout.tab_film_info, container,
>> > >>> false);
>> >
>> > >>>         return view;
>> > >>>     }
>> >
>> > >>>     /*
>> > >>>     @Override
>> > >>>     public void onSaveInstanceState(Bundle outState) {
>> > >>>         super.onSaveInstanceState(outState);
>> >
>> > >>>     }*/
>> >
>> > >>>     @Override
>> > >>>     public void onCreate(Bundle savedInstanceState) {
>> > >>>         super.onCreate(savedInstanceState);
>> >
>> > >>>         act =  (Detail) getActivity();
>> >
>> > >>>     }
>> >
>> > >>>     @Override
>> > >>>     public void onActivityCreated(Bundle savedInstanceState) {
>> > >>>         super.onActivityCreated(savedInstanceState);
>> > >>>         new DownloadFilmDetailAsyncTask().execute();
>> >
>> > >>>     }
>> >
>> > >>>     private class DownloadFilmDetailAsyncTask extends 
>> AsyncTask<Void,
>> > >>> DetailedRec, Void>
>> > >>>     {
>> >
>> > >>>         @Override
>> > >>>         protected void onPreExecute() {
>> >
>> > >>>             super.onPreExecute();
>> >
>> > >>>         }
>> >
>> > >>>         @Override
>> > >>>         protected void onPostExecute(Void result) {
>> >
>> > >>>             super.onPostExecute(result);
>> >
>> > >>>             ProgressBar prBar =
>> > >>> (ProgressBar)getView().findViewById(R.id.progressbar_film);
>> > >>>             prBar.setVisibility(View.GONE);
>> > >>>             ScrollView lay =
>> > >>> (ScrollView)getView().findViewById(R.id.tab_filmsummary);
>> > >>>             lay.setVisibility(View.VISIBLE);
>> >
>> > >>>         }
>> >
>> > >>>         @Override
>> > >>>         protected Void doInBackground(Void... params)
>> > >>>         {
>> > >>>             try
>> > >>>             {
>> >
>> > >>>                 String locale =
>> > >>> getResources().getConfiguration().locale.getDisplayName();
>> >
>> > >>>                 JSONObject objSend = new JSONObject();
>> > >>>                 objSend.put("idFilm", act.getIdFilm());
>> > >>>                 objSend.put("cinemaId",act.getIdCinema());
>> > >>>                 int ind = locale.indexOf("(");
>> > >>>                 String locale_send = locale.substring(0, ind-1);
>> > >>>                 objSend.put("locale", locale_send);
>> > >>>                 ArrayList<String> otherCin = new
>> > >>> ArrayList<String>(Arrays.asList(act.getOtherCinemas()));
>> > >>>                 JSONArray othCin = new JSONArray(otherCin);
>> > >>>                 objSend.put("otherCinemas", othCin );
>> > >>>                 JSONObject jsonObject =
>> > >>> 
>> sendAndGetJSONObject(JSON_SERVER+"JsonServer?op=getFilmbyId",objSend);
>> >
>> > >>>                 DetailedRec detail_rec = new DetailedRec();
>> > >>>                 //FILM
>> > >>>                 
>> detail_rec.setFilmId(jsonObject.getString("filmId"));
>> > >>>                 detail_rec.setName(jsonObject.getString("name"));
>> >
>> > >>> 
>> detail_rec.setImageUrl(jsonObject.getString("imageUrl").replace("640",
>> > >>> "80"));
>> > >>>                 
>> detail_rec.setActors(jsonObject.getString("actors"));
>> > >>>                 detail_rec.setGenre(jsonObject.getString("genre"));
>> >
>> > >>> detail_rec.setDirector(jsonObject.getString("director"));
>> > >>>                 detail_rec.setPlot(jsonObject.getString("plot"));
>> > >>>                 detail_rec.setYear(jsonObject.getString("year"));
>> >
>> > >>> detail_rec.setDuration(jsonObject.getString("duration"));
>> >
>> > >>> detail_rec.setTrailer(jsonObject.getString("trailer"));
>> > >>>                 
>> detail_rec.setRating(jsonObject.getString("rating"));
>> >
>> > >>>                 detail_film = detail_rec;
>> > >>>                 publishProgress(detail_rec);
>> >
>> > >>>             }
>> > >>>             catch (IOException ignored)
>> > >>>             {
>> > >>>             }
>> > >>>             catch (JSONException ignored)
>> > >>>             {
>> > >>>             }
>> > >>>             return null;
>> > >>>         }
>> >
>> > >>>         @Override
>> > >>>         protected void onProgressUpdate(DetailedRec...
>> >
>> > ...
>> >
>> > read more »
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Android Developers" group.
>> To post to this group, send email to 
>> [email protected]<javascript:>
>> To unsubscribe from this group, send email to
>> [email protected] <javascript:>
>> For more options, visit this group at
>> http://groups.google.com/group/android-developers?hl=en
>>
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to