Autore Topic: Custom ListView in Viewpager  (Letto 393 volte)

Offline Lucart98

  • Nuovo arrivato
  • *
  • Post: 12
  • Respect: 0
    • Mostra profilo
  • Dispositivo Android:
    Nexus 5 (32GB, Nero)
  • Sistema operativo:
    Windows 7
Custom ListView in Viewpager
« il: 07 Aprile 2014, 20:09:33 CEST »
0
Ecco la pagina:
Codice (Java): [Seleziona]
package[...]
import [...]
public class Home extends FragmentActivity {
    ViewPager mViewPager;
    ListView list;
    row_video_Adapter adapter;
    public  Home CustomListView = null;
    public  ArrayList<ModelloLista> CustomListViewValuesArr = new ArrayList<ModelloLista>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);

        // Create the adapter that will return a fragment for each of the three
        // primary sections of the app.
        mSectionsPagerAdapter = new SectionsPagerAdapter(
                getSupportFragmentManager());

        // Set up the ViewPager with the sections adapter.
        mViewPager = (ViewPager) findViewById(R.id.pager);
        mViewPager.setAdapter(mSectionsPagerAdapter);

        // ListView
        CustomListView = this;

        /******** Take some data in Arraylist ( CustomListViewValuesArr ) ***********/
        setListData();

        Resources res =getResources();
        list= (ListView)findViewById(R.id.section_label);  // List defined in XML ( See Below )

        /**************** Create Custom Adapter *********/
        adapter=new row_video_Adapter(CustomListView, CustomListViewValuesArr,res);
        list.setAdapter(adapter);
    }
    /****** Function to set data in ArrayList *************/
    public void setListData(){
        final ModelloLista sched = new ModelloLista();
        sched.setTitolo("Video 1");
        sched.setImmagine("video_preview");
        sched.setUrl("http:\\www.com");
        CustomListViewValuesArr.add(sched);
    }


   /*****************  This function used by adapter ****************/
    public void onItemClick(int mPosition){
        ModelloLista tempValues = ( ModelloLista ) CustomListViewValuesArr.get(mPosition);


       // SHOW ALERT
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.home, menu);
        return true;
    }
    public class SectionsPagerAdapter extends FragmentPagerAdapter {
        public SectionsPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            Fragment fragment = new DummySectionFragment();
            Bundle args = new Bundle();
            args.putInt(DummySectionFragment.ARG_SECTION_NUMBER, position + 1);
            fragment.setArguments(args);
            return fragment;
        }

        @Override
        public int getCount() {
            // Show 5 total pages.
            return 5;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            Locale l = Locale.getDefault();
            switch (position) {
            case 0:
                return getString(R.string.title_section1).toUpperCase(l);
            case 1:
            [...]
            }
            return null;
        }
    }
    public static class DummySectionFragment extends Fragment {
        public static final String ARG_SECTION_NUMBER = "section_number";
        public DummySectionFragment() {
        }
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_home_dummy,
                    container, false);
            //TextView dummyTextView = (TextView) rootView.findViewById(R.id.section_label);
            switch(getArguments().getInt(ARG_SECTION_NUMBER)){
                case 1:
                    //dummyTextView.setText("text 1");
                    break;
                case 2:
                [...]
            }
            return rootView;
        }
    }
}

Come posso gestire la ListView dal DummySectionFragment?
Ho provato ad inserire il codice relativo alla ListView nello switch ottenendo nient'altro che errori.

Grazie mille :D