Skip to content Skip to sidebar Skip to footer

How To Bind Data In Gridview Found In Fragment In Android App?

I have a fragment class and its layout is in xml. Inside the xml fragment layout is the gridview. I wanted the gridview to show the data. What happens is that when I run the androi

Solution 1:

i think you want these ad.notifyDataSetChanged();

Solution 2:

Might be wrong, but it seems like you are setting the adapter before inflating the layout. This will cause a problem because before you inflate the layout, the gridview doesn't exist and grid.setAdapter(...) will throw a NullPointerException. Try moving the following snippet from the onCreateView(...) to onActivityCreated(...), after calling super.onActivityCreated(...):

final String [] items=newString[]{"Item1","Item2","Item3","Item4"};
ArrayAdapter ad=newArrayAdapter<String>
     (this.getActivity().getApplicationContext(),R.layout.frontpage,items);

View fragmentView=getView();    
GridView grid=(GridView)fragmentView.findViewById(R.id.forApprovalOrders);
grid.setAdapter(ad);

Solution 3:

Have you tried this:

    View fragmentView= inflater.inflate(R.layout.frontpage, container, false); 
    GridView grid=(GridView)fragmentView.findViewById(R.id.forApprovalOrders);
    grid.setAdapter(ad);

    // Inflate the layout for this fragmentreturn fragmentView;

If it's not solved, what is the error message and at what line did it stop while debugging?

Post a Comment for "How To Bind Data In Gridview Found In Fragment In Android App?"