-3

I can't able to understand the logic of layout inflater What is use the of layout inflater in adapetr class.

public class WordAdapter extends ArrayAdapter<Word> {


    public WordAdapter(Activity context, ArrayList<Word> words) {
        // Here, we initialize the ArrayAdapter's internal storage for the context and the list.
        // the second argument is used when the ArrayAdapter is populating a single TextView.
        // Because this is a custom adapter for two TextViews and an ImageView, the adapter is not
        // going to use this second argument, so it can be any value. Here, we used 0.
        super(context, 0, words);

    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        // Check if the existing view is being reused, otherwise inflate the view
        View listItemView = convertView;
        if (listItemView == null) {
            listItemView = LayoutInflater.from(getContext()).inflate(R.layout.list_item, parent, false);
        }
Shubham Kumar
  • 295
  • 3
  • 13
  • Check if [this](https://stackoverflow.com/questions/51729036/what-is-a-layoutinflater-and-how-do-i-use-it-properly/51729037#51729037) one helps. – Bertram Gilfoyle Aug 07 '18 at 16:24

1 Answers1

0

You can go through the Android Official Documentation.

LayoutInflater (which coverts an XML layout file into corresponding ViewGroups and Widgets) and the way it inflates Views inside Fragment’s onCreateView() method.

LayoutInflater is a class used to instantiate layout XML file into its corresponding view objects which can be used in java programs.

Satan Pandeya
  • 3,747
  • 4
  • 27
  • 53
Android Geek
  • 8,956
  • 2
  • 21
  • 35