CustomArrayAdapter Implementation:Unable to get the resource id

前端 未结 4 604
走了就别回头了
走了就别回头了 2021-01-19 01:12

I want to implement CustomArrayAdapter and following is the constructor I have written for my custom adapter

public CustomUsersAdapter(Context context, Array         


        
4条回答
  •  耶瑟儿~
    2021-01-19 01:49

     I dont know which resource ID is being referred here.
    

    Since you put 0 in the second parameter of the constructor it wont have any reference to any layout

    as the documentation is saying:

     resource   The resource ID for a layout file containing a layout to use when instantiating views.
    

    Now if you put an existing layout to the constructor then that layout will be use to instantiate the view of your listViewItems but you need to override the getView method to enable you to design which text goes where in your layout.

    If you are planning to put an existing layout then use another constructor on it:

    public ArrayAdapter (Context context, int resource, T[] objects)
    

    But for design I wont really add any resource layout to the constructor but directly inflate the view in your getView method and return that view.

提交回复
热议问题