【问题标题】:Gridview in fragment片段中的网格视图
【发布时间】:2013-05-09 14:21:52
【问题描述】:

我试图在布局中使用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);引起的

【问题讨论】:

    标签: android layout view


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2014-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-12
      • 2021-11-26
      • 2020-09-28
      • 1970-01-01
      相关资源
      最近更新 更多