Custom Adapter Not showing data

妖精的绣舞 提交于 2019-12-03 21:07:06

You can simple implement onCreateView() for Fragment.

 ListView menuList;

 @Override
 public View onCreateView(LayoutInflater inflater,
  ViewGroup container, Bundle savedInstanceState) {

  // Inflate the layout for this fragment

    View rootView;
    rootView = inflater.inflate(R.layout.fragment_create_new_order_list_sections, container, false); 
    menuList=(ListView) rootView.findViewById(R.id.bearer_menu_order_list);
    DatabaseHelper helper=new DatabaseHelper(getActivity());
    listMenu = helper.getMenuItem();
    Log.e("list menu--",listMenu.size()+"");
    MenuListAdapter adapter=new MenuListAdapter(getActivity(),listMenu);
    Log.e("list adapter--",""+adapter.getCount());
    menuList.setAdapter(adapter);
    menuList.setVisibility(View.VISIBLE);
   return rootView;
 }

And in your Adapter class change here also

 public class MenuListAdapter extends BaseAdapter {
 private List<MenuData> list;
 private Context context;

 public MenuListAdapter(Context context, List<MenuData> list) {
    this.context = context;
    this.list = list;
    Log.e("Hee",list.size()+"");
 }

Remove all the code from onActivityCreated() method.

Try this way:

 ListView menuList;
 public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View rootView;
    rootView = inflater.inflate(R.layout.fragment_create_new_order_list_sections, container, false);

    menuList=(ListView) rootView.findViewById(R.id.bearer_menu_order_list);
    DatabaseHelper helper=new DatabaseHelper(getActivity());
    listMenu = helper.getMenuItem();
    Log.e("list menu--",listMenu.size()+"");
    MenuListAdapter adapter=new MenuListAdapter(getActivity(),listMenu);
    Log.e("list adapter--",""+adapter.getCount());
    menuList.setAdapter(adapter);
    menuList.setVisibility(View.VISIBLE);

    return rootView;
}

And remove all the code from onActivityCreated(....) and give me feedback on this.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!