Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/225.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Viewpager中的自定义ListView_Java_Android_Android Fragments_Custom Adapter - Fatal编程技术网

Java Viewpager中的自定义ListView

Java Viewpager中的自定义ListView,java,android,android-fragments,custom-adapter,Java,Android,Android Fragments,Custom Adapter,这是我的页面: package[...] import [...] public class Home extends FragmentActivity { ViewPager mViewPager; ListView list; row_video_Adapter adapter; public Home CustomListView = null; public ArrayList<ModelloLista> CustomListVie

这是我的页面:

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;
        }
    }
}
包[…]
进口[……]
公共类家庭扩展了碎片化活动{
ViewPager mViewPager;
列表视图列表;
行视频适配器;
公共主页CustomListView=null;
public ArrayList CustomListViewValuesArrayList=新ArrayList();
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
//创建适配器,该适配器将为这三个函数中的每一个返回一个片段
//应用程序的主要部分。
mSectionsPagerAdapter=新节spageradapter(
getSupportFragmentManager());
//使用分区适配器设置ViewPager。
mViewPager=(ViewPager)findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
//列表视图
CustomListView=这个;
/********在Arraylist(CustomListViewValuesArrayList)中获取一些数据***********/
setListData();
Resources res=getResources();
list=(ListView)findViewById(R.id.section_label);//用XML定义的列表(见下文)
/****************创建自定义适配器*********/
适配器=新行\视频\适配器(CustomListView、CustomListViewValuesArr、res);
list.setAdapter(适配器);
}
/******函数设置ArrayList中的数据*************/
public void setListData(){
最终ModelloLista sched=新ModelloLista();
附表setTitolo(“视频1”);
附表SetimEngine(“视频预览”);
sched.setUrl(“http:\\www.com”);
CustomListViewValuesArr.add(附表);
}
/*****************此函数由适配器使用****************/
公共空间链接(集成){
ModelloLista tempValues=(ModelloLista)CustomListViewValuesArr.get(mPosition);
//显示警惕
}
@凌驾
公共布尔onCreateOptions菜单(菜单){
getMenuInflater().充气(R.menu.home,menu);
返回true;
}
公共类节SpagerAdapter扩展了FragmentPagerAdapter{
公共部分SpagerAdapter(碎片管理器fm){
超级(fm);
}
@凌驾
公共片段getItem(int位置){
Fragment Fragment=新的DummySectionFragment();
Bundle args=新Bundle();
args.putInt(DummySectionFragment.ARG_节号,位置+1);
fragment.setArguments(args);
返回片段;
}
@凌驾
public int getCount(){
//显示共5页。
返回5;
}
@凌驾
公共字符序列getPageTitle(int位置){
Locale l=Locale.getDefault();
开关(位置){
案例0:
返回getString(R.string.title_section1).toUpperCase(l);
案例1:
[...]
}
返回null;
}
}
公共静态类DummySectionFragment扩展了片段{
公共静态最终字符串ARG\u SECTION\u NUMBER=“SECTION\u NUMBER”;
公共数据段(){
}
@凌驾
创建视图上的公共视图(布局、充气机、视图组容器、,
Bundle savedInstanceState){
视图根视图=充气机。充气(R.layout.fragment\u home\u dummy,
货柜(虚假);;
//TextView dummyTextView=(TextView)rootView.findViewById(R.id.section\u标签);
开关(getArguments().getInt(参数节号)){
案例1:
//dummyTextView.setText(“文本1”);
打破
案例2:
[...]
}
返回rootView;
}
}
}
如何将自定义ListView放入片段中? 我试图移动
开关(getArguments().getInt(ARG_SECTION_NUMBER)){
中的代码,但出现了许多错误。
我该怎么办?

你能在片段布局中创建一个自定义列表视图,然后简单地将其添加到寻呼机中吗?@Eenvincible我该怎么做?