花果山牛哥哥 2016-11-06 08:06 采纳率: 50%
浏览 1061
已采纳

安卓 oncreateview 不能绑定布局文件

    @Override
    protected void onPostExecute(Void result) {

      newTestLv = (ListView) getActivity().findViewById(R.id.test_huiyuan_lv);
      TextView noNetwork = (TextView) getActivity().findViewById(R.id.test_huiyuan_empty_tv);
      newTestLv.setEmptyView(noNetwork);

      mAdapter = new TestSingleAdapter(getActivity(),newTestList);

      newTestLv.setAdapter(mAdapter);
      mAdapter.notifyDataSetChanged(); 
      //注册上下文菜单
      //registerForContextMenu(newProblemLv);


      if (newTestList != null && !newTestList.isEmpty()) {
          noNetwork.setVisibility(View.GONE);
      } else {
          noNetwork.setVisibility(View.VISIBLE);
      }
      newTestLv.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> listView, View itemView, int index, long id) {

                Test test = newTestList.get(index);
                Bundle bundle = new Bundle();
                bundle.putSerializable("TEST", test);
                UiHelper.showFragment(FragmentHuiyuan.this, bundle, new TestDetailFragment());
            }           
        });
      newTestLv.setOnScrollListener(new OnScrollListener() {
            @Override
            public void onScrollStateChanged(AbsListView view, int scrollState) { }

            @Override
            public void onScroll(AbsListView listView, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
                int lastItemIndex = listView.getLastVisiblePosition();//当前屏幕最后一条记录ID
                if(lastItemIndex + 1 == totalItemCount && isLoadFinish){//判断往下是否达到数据最后一条记录
                    //锁定加载完成标志
                    isLoadFinish = false;
                    //根据页码获取最新数据
                    try {
                        addDataAtBackground();
                    } catch (Exception e) {
                        e.printStackTrace();
                    } 
                }
            }
        });

        if(NetWorkHelper.isNetworkConnected(mApp)){
            addDataAtBackground();
        }else{
            noNetwork.setText("网络未连接,请检查移动数据是否打开或点击标题栏刷新");
            noNetwork.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    mApp.postEvent(new OnReceivedRefreshNewsShownEvent(NoticeType.NOTIFICATION));
                }
            });
        } 
    }
  }
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    return UiHelper.getLightThemeView(getActivity(), R.layout.fragment_test_huiyuan);
}

@Override
public void onViewCreated(View v, Bundle savedInstanceState) {
    super.onViewCreated(v, savedInstanceState);
    //TextView title = (TextView) v.findViewById(R.id.title_text);
    //title.setText("会员测试");

    new RemoteDataTask().execute();
}



    布局文件:
    <?xml version="1.0" encoding="utf-8"?>

android:layout_width="match_parent"
android:layout_height="match_parent" >
android:id="@+id/the_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>

<ListView 
    android:id="@+id/test_huiyuan_lv"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:listSelector="#00000000"
    android:cacheColorHint="#00000000"
    android:divider="@color/xian_yanse"
    android:dividerHeight="1px"
    android:scrollbars="@null"
    android:layout_below="@+id/the_title" 
   />

<TextView
    android:id="@+id/test_huiyuan_empty_tv"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:gravity="center"
    android:textColor="@color/blue"
    android:text="@string/isNetwork"
    android:padding="20dp"
    android:visibility="gone" />

报错信息:
图片说明

有没有朋友遇到相同的问题,我已经在这里卡住了两天了

  • 写回答

3条回答 默认 最新

  • DarrenHang.L 2016-11-07 08:24
    关注

    应该是你父容器没有获取到,你试试用inflater泵一个布局,不用这个 UiHelper.getLightThemeView(getActivity(), R.layout.fragment_test_huiyuan)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器