2017-08-08 46 views
-3

我無法理解佈局充氣器的邏輯 在adapetr類中佈置充氣器有什麼用處。什麼是佈局充氣器?

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); 
     } 

回答

0

根據官方文檔:

實例化佈局的XML文件到相應的視圖對象。

欲瞭解更多詳細信息,請查詢android documentation

0

您可以通過Android Official Documentation

LayoutInflater(將XML佈局文件轉換爲相應的ViewGroups和Widgets)以及它在Fragment的onCreateView()方法內部充斥Views的方式。

LayoutInflater是一個類,用於將佈局XML文件實例化爲可用於Java程序的相應視圖對象。