ViewPager,Fragment,活动在不活动后恢复GridView消失

时间:2012-11-26 13:52:17

标签: android gridview android-viewpager

有没有人对此有答案。我看过所有代码,但无法弄明白?有没有onResume等我忘了? 我使用自定义GridViewAdapter 感谢

更新:

public static void bindGridView(final Activity context) {
    if (mGridView == null) {
        mGridView = (GridView)v.findViewById(R.id.grid_view_n1);
    }
    mFavortieAdapter = new GridViewInfo(context,FavoriteTextList, FavoriteDrawableList, FavoriteID);
    mGridView.setAdapter(mFavortieAdapter);
    mGridView.setSelection(0);

    // Implement On Item click listener
    mGridView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int position,
                long arg3) {
            String db_int = FavoriteIntent.get(position);
            getApplicationName(db_int, context);
        }
    });
}

这在onCreate中被调用。

1 个答案:

答案 0 :(得分:0)

DeeV让我朝着正确的方向前进。我调查了GridView是如何保存/重建的,显然在恢复后gridView不为null,因此不再调用。

从此行中删除了if语句:

if (mGridView == null) {
    mGridView = (GridView)v.findViewById(R.id.grid_view_n1);
}

感谢DeeV