android - fragment 中的 Gridview

标签 android layout view

我正在尝试在布局中使用 GridView,但我的代码说我不能对非静态方法进行静态引用。我认为在 Fragment 中使用 GridViewActivity

相同

这是我的代码:

public static class MiscFragment extends Fragment {
    /**
     * The fragment argument representing the section number for this
     * fragment.
     */
    public static final String ARG_SECTION_NUMBER = "section_number";

    public MiscFragment() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.misc_fragment,
                container, false);

        GridView gridview = (GridView) findViewById(R.id.gridview);
        return rootView;
    }
}

然后我会将 gridview 设置为 Adapter。目前问题是由findViewById(R.id.gridview);

引起的

最佳答案

您应该使用 rootView.findViewById(R.id.gridview)

关于android - fragment 中的 Gridview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16464049/

相关文章:

asp.net-mvc-3 - 类型 'System.Web.IHtmlString' 在未引用的程序集中定义

javascript - Backbone : Call an extended view's overridden render() function

android - 在 Release模式下检查互联网连接不起作用

java - 当Android方法被贬值时我该怎么办?

java - 更改 NavigationView 中项目的样式

java - LinearLayout不出现

javascript - ExtJS 和 Internet Explorer : Layout corruption with scrollbars

Android [GetToken] GetToken 失败,状态代码为 : UNREGISTERED_ON_API_CONSOLE

android - 循环遍历Android View 的所有 subview ?

android - 如何更改 View 的可见性?