Hi,
I'm developing an application for Galaxy Tab (api level 8) and I have
found a problem.

I use a pageadapter with 2 fragments, MainCLIFrag and AssArtCliFrag,
under the relevant code:

the problem is:
in the MainCLIFrag I have a search button for choosing a customer from
a list (I show a ListActivity), after chosen,
in the MainCLIFrag I show the Customer Detail and in the AssArtCliFrag
the list of his orders;
if I change the customer, in the MainCLIFrag I communicate to the
AssArtCliFrag that the customer was changed, so, the orders are
refreshed.

Everything works until the configuration changes (screen rotation for
example), in this case, the variabile view in the AssArtCliFrag
becomes null, and I'm not able to refresh the orders anymore, even
getActivity() is null.

To get again the orders, I have to go AssArtCliFrag, rotate the
screen, so, the event onCreateView fires and the view will be set
again.

That is very annoying and I don't know how to solve it.

Any suggestion will be highly appreciated,

thank you.

Davide.

*************** FragmentActivity

public class ViewPagerFragmentActivity extends FragmentActivity
implements OnCustomerSelectedListener {
        private PagerAdapter mPagerAdapter;

        @Override
        public void onCustomerSelected(String CodCli)
        {

                AssArtCliFrag fragmentB = (AssArtCliFrag) 
mPagerAdapter.getItem(1);

                fragmentB.SelectAss(CodCli);
        }

..................... and in the onCreate ...
                List<Fragment> fragments = new Vector<Fragment>();
                fragments.add(Fragment.instantiate(this,
MainCLIFrag.class.getName()));
                fragments.add(Fragment.instantiate(this,
AssArtCliFrag.class.getName()));
                mPagerAdapter  = new 
PagerAdapter(super.getSupportFragmentManager(),
fragments);
                ViewPager pager = (ViewPager)super.findViewById(R.id.viewpager);
                pager.setAdapter(mPagerAdapter);
.....................

*************** AssArtCliFrag

public class AssArtCliFrag extends ListFragment {
        private SimpleCursorAdapter mAdapter;
        private View view;

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup
container, Bundle savedInstanceState) {
                if (container == null) {
            return null;
        }
                view = (LinearLayout)inflater.inflate(R.layout.assartcli, 
container,
false);

                CreateFields();

                return view;
        }

        public void SelectAss(String CodCli)
        {
                Cursor cursor = GetCursor(CodCli);
                mAdapter.changeCursor(cursor);
                mAdapter.notifyDataSetChanged();
        }

        private Cursor GetCursor(String CodCli)
        {
                try {
                AgenteProvider ap = new AgenteProvider(view.getContext());
                String sql = "SELECT COD_ART AS _id, COD_ART, DES_ART, DAT_ULT,
" +
                                     "QTA_ULT, PRZ_ULT FROM ASSORCLI" +
                                         " WHERE COD_CLI = '" + CodCli + "'";

                Cursor MyCursor = ap.Articoli.CursorART(sql);
                if (AgenteProvider.ErrorMessage != "")
                        DisplayError(AgenteProvider.ErrorMessage);
                getActivity().startManagingCursor(MyCursor);

                return MyCursor;

                } catch (Exception e) {
                        DisplayError(e.toString());
                        return null;
                }
        }

*************** MainCLIFrag

public class MainCLIFrag extends Fragment {
............................
............................
    OnCustomerSelectedListener mListener;

    public interface OnCustomerSelectedListener {
        public void onCustomerSelected(String CodCli);
    }

    @Override
        public void onAttach(Activity activity) {
                super.onAttach(activity);
        try {
                mListener = (OnCustomerSelectedListener) activity;
        }
        catch (ClassCastException e) {
                throw new ClassCastException(activity.toString() + " must 
implement
OnCustomerSelectedListener");
        }
        }

    public void CliSelected(String CodCli)
    {
        mListener.onCustomerSelected(CodCli);
    }

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

Reply via email to