Dynamicaly loading data to Gridview

前端 未结 2 693
别跟我提以往
别跟我提以往 2021-01-22 06:27

While i am working on gridview i faced following problems, any help will be appreciated,

  1. When I load data to my gridview it loads only first 3 items of the arr

2条回答
  •  一生所求
    2021-01-22 07:02

    First, change your adapter to expends the

    extends ArrayAdapter
    

    Change the constructor: public CustomGrid(Context c) { super(c, R.layout.fragment_pizza); } Now Change getView() method:

    // Get the item
            String item = getItem(position);
    

    Set this item text to your view and if you require more data sets, create the model class and change extends ArrayAdapter with extends ArrayAdapter and

     // Get the item
                ModelClass item = getItem(position);
    

    Now in your Activity class, initilize the ModelClass, set it's variables and add to the adapter using add or addAll methods.

提交回复
热议问题