Android 我必须单击两次才能使其工作,滚动或单击事件

Android 我必须单击两次才能使其工作,滚动或单击事件,android,android-viewpager,Android,Android Viewpager,我有一个有6页的viewPager,每页都有一个PullToRefreshGridView。 我发现我必须单击两次才能触发单击事件或滚动GridView。 第一次单击没有触发单击事件。 这6页有相同的情况 请有人帮我调试一下,告诉我我做错了什么 这是我的代码: viewPager = (ViewPager)findViewById(R.id.viewPager); adapterViewPager = new MyPagerAdapter(getSupportFragmentManage

我有一个有6页的viewPager,每页都有一个
PullToRefreshGridView
。 我发现我必须单击两次才能触发单击事件或滚动GridView。 第一次单击没有触发单击事件。 这6页有相同的情况

请有人帮我调试一下,告诉我我做错了什么

这是我的代码:

viewPager = (ViewPager)findViewById(R.id.viewPager);
    adapterViewPager = new MyPagerAdapter(getSupportFragmentManager());
    viewPager.setAdapter(adapterViewPager);
    viewPager.setCurrentItem(0);
    viewPager.addOnPageChangeListener(this);
    viewPager.setOffscreenPageLimit(0);
MyPagerAdapter是:

public static class MyPagerAdapter extends FragmentStatePagerAdapter {
    private static int NUM_ITEMS = 6;

        public MyPagerAdapter(FragmentManager fragmentManager) {
            super(fragmentManager);
        }

        @Override
        public void destroyItem(View collection, int position, Object o) {
            Log.d("DESTROY", "destroying view at position " + position);
            View view = (View) o;
            ((ViewPager) collection).removeView(view);
            view = null;
        }

        // Returns total number of pages
        @Override
        public int getCount() {
            return NUM_ITEMS; 
        }

        // Returns the fragment to display for that page
        @Override
        public Fragment getItem(int position) {

            switch (position) 
            {
            case 0:
                return TypeZero.newInstance("", "Page # 1");
            case 1:
                return TypeOne.newInstance("", "Page # 2");
            case 2:
                return TypeTwo.newInstance("", "Page # 3");
            case 3:
                return TypeThree.newInstance("", "Page # 4");
            case 4:
                return TypeFour.newInstance("", "Page # 5");
            case 5:
                return TypeFive.newInstance("", "Page # 6");
                default:
                    return null;
            }
        }

        // Returns the page title for the top indicator
        @Override
        public CharSequence getPageTitle(int position) {
            switch(position)
            {
            case 0:
                return "Zero";
            case 1:
                return "One";
            case 2:
                return "Two";
            case 3:
                return "Three";
            case 4:
                return "Four";
            case 5:
                return "Five";
            default:
                return null;
            }
        }
这是我的布局活动_main.xml

<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<android.support.v7.widget.Toolbar 
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:background="#556fa5"
    android:minHeight="?attr/actionBarSize">
    </android.support.v7.widget.Toolbar>


<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/toolbar">


    <RelativeLayout
        android:id="@+id/main_content"
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.design.widget.TabLayout
            android:id="@+id/tabLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabIndicatorColor="#f44336"
            app:tabSelectedTextColor="#FFFFFF"
            app:tabTextColor="#03A9F4" />

        <android.support.v4.view.ViewPager
            android:id="@+id/viewPager"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@id/tabLayout" />

    </RelativeLayout>

    <!-- Listview to display slider menu -->

    <ListView
        android:id="@+id/list_slidermenu"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:choiceMode="singleChoice"
        android:divider="@color/list_divider"
        android:dividerHeight="1dp"        
        android:listSelector="@drawable/list_selector"
        android:background="@color/list_background"/>
</android.support.v4.widget.DrawerLayout>   

请在设置适配器之前尝试此操作

viewPager.invalidate();  
viewPager.requestLayout();

请在设置适配器之前尝试此操作

viewPager.invalidate();  
viewPager.requestLayout();
我发现我添加了

main_layout.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
viewPager
内的
gridview
的每个活动中。 这一个导致焦点
false

我发现我添加了

main_layout.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
viewPager
内的
gridview
的每个活动中。
这会导致焦点
false

您可以发布布局文件吗?您是否已将任何视图或父布局的焦点设置为false?问题可能是您正在请求对布局上的任何视图进行聚焦。请在布局文件中检查相同的内容。@BaluSKT:我已经添加了我的layout@RageshRamesh:我已尝试将focusable和focusableInTouchMode设置为false,它不起作用。你能发布布局文件吗?你有没有将任何视图或父布局的focusability设置为false?问题可能是你正在请求布局上任何视图的requestfocus。请在布局文件中检查相同的内容。@BaluSKT:我已经添加了我的layout@RageshRamesh:我已尝试将focusable和focusableInTouchMode设置为false,但它不起作用。感谢您的回复,但它不起作用。感谢您的回复,但它不起作用。