Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.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
Android 使用查看寻呼机和ListActivity在多个页面中显示json结果_Android_Json_Arraylist_Android Viewpager_Listactivity - Fatal编程技术网

Android 使用查看寻呼机和ListActivity在多个页面中显示json结果

Android 使用查看寻呼机和ListActivity在多个页面中显示json结果,android,json,arraylist,android-viewpager,listactivity,Android,Json,Arraylist,Android Viewpager,Listactivity,目前,我正在ListActivity中获取JSON格式的结果,并将它们添加到4 ArrayList中。 我已经为四个不同的页面设置了ViewPagers。 我的布局如下: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent"

目前,我正在ListActivity中获取JSON格式的结果,并将它们添加到4 ArrayList中。 我已经为四个不同的页面设置了ViewPagers。 我的布局如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/bg_gradient"
    android:orientation="vertical" >

    <ListView
        android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" /> 

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/bg_gradient" />

</LinearLayout>
现在的问题是,如果我不调用获取结果的类,视图寻呼机工作正常,我可以在页面之间滑动

但是当我调用获取结果的类时,视图寻呼机不起作用

我是说如果我调用所有4个setListAdapter

setListAdapter(adapter1);
setListAdapter(adapter2);
setListAdapter(adapter3);
setListAdapter(adapter4); 
 setListAdapter(adapter1);
 //setListAdapter(adapter2);
//setListAdapter(adapter3);
//setListAdapter(adapter4);   
它只显示第四页,我无法滑动到任何页面

如果我只调用一个setListAdapter

setListAdapter(adapter1);
setListAdapter(adapter2);
setListAdapter(adapter3);
setListAdapter(adapter4); 
 setListAdapter(adapter1);
 //setListAdapter(adapter2);
//setListAdapter(adapter3);
//setListAdapter(adapter4);   
我只能看到第一页,而且我无法在页面之间滑动

谷歌搜索了一下,发现可以使用
片段
,但我不想再修改代码了。有人能帮我解决这个问题吗

我的CustomPagerAdapter为:

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class CustomPagerAdapter extends PagerAdapter {

    private Context mContext;

    public CustomPagerAdapter(Context context) {
        mContext = context;
    }

    @Override
    public Object instantiateItem(ViewGroup collection, int position) {
        CustomPagerEnum customPagerEnum = CustomPagerEnum.values()[position];
        LayoutInflater inflater = LayoutInflater.from(mContext);
        ViewGroup layout = (ViewGroup) inflater.inflate(customPagerEnum.getLayoutResId(), collection, false);
        collection.addView(layout);
        return layout;
    }

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

    @Override
    public int getCount() {
        return CustomPagerEnum.values().length;
    }


    @Override
    public CharSequence getPageTitle(int position) {
        CustomPagerEnum customPagerEnum = CustomPagerEnum.values()[position];
        return mContext.getString(customPagerEnum.getTitleResId());
    }

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

    }

}
编辑1: 添加布局代码: 这些布局如下:

`<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#5fb0c9"
    android:orientation="vertical"
    android:scrollbarAlwaysDrawVerticalTrack="true" >

    <RelativeLayout
        android:id="@+id/relativeLayout1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="30dp"
        android:layout_marginRight="30dp"
        android:layout_marginTop="40dp"
        android:background="#fff"
        android:orientation="vertical"
        android:padding="20dp" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:paddingTop="30dp" >

            <TextView
                android:id="@+id/title"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:paddingLeft="50dp"
                android:textSize="17dip"
                android:text="Kacha Bazaar"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/itemName"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:paddingLeft="50dp"
                android:textSize="17dip"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/category"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:paddingLeft="50dp"
                android:paddingTop="30dp" />
        </LinearLayout>
    </RelativeLayout>

</ScrollView>`
`
`

您没有在
查看页面
上设置
适配器
s。您正在主布局的
列表视图中设置它们。一旦你在上面设置了一个
适配器
,那么
列表视图
——它有
环绕内容
高度——就会填充布局,并将
视图页面
从底部推出,这就是为什么它看起来不再工作的原因。
setListAdapter()
方法只能在自己的布局中使用ID
android.R.ID.list
ListView
R.layout.menu\u kacha\u bazaar,R.layout.menu\u mudi,R.layout.menu\u mishti,R.layout.menu_rannar_sarjam
这些是
查看页面
的页面。这些是您用于
SimpleAdapter
中列表项的布局。我真的不认为你的意思是把它们也用于
ViewPager
的页面。似乎在每个页面布局中都需要一个
ListView
。添加了
R.layout.menu\u kacha\u bazaar
code。我想在
ViewPager
的页面
setListAdapter(adapter1)中使用的这些页面中显示结果正在设置第一页的数据。我是说第1页的数据很好用。问题是,我无法在页面之间滑动,只加载了一个页面。
`<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#5fb0c9"
    android:orientation="vertical"
    android:scrollbarAlwaysDrawVerticalTrack="true" >

    <RelativeLayout
        android:id="@+id/relativeLayout1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="30dp"
        android:layout_marginRight="30dp"
        android:layout_marginTop="40dp"
        android:background="#fff"
        android:orientation="vertical"
        android:padding="20dp" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:paddingTop="30dp" >

            <TextView
                android:id="@+id/title"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:paddingLeft="50dp"
                android:textSize="17dip"
                android:text="Kacha Bazaar"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/itemName"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:paddingLeft="50dp"
                android:textSize="17dip"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/category"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:paddingLeft="50dp"
                android:paddingTop="30dp" />
        </LinearLayout>
    </RelativeLayout>

</ScrollView>`