How to inflate Android View in LinearLayout class?

后端 未结 3 1929
深忆病人
深忆病人 2021-01-04 18:17

I\'ve got a little piece of xml, which I\'ll be using in a lot of places in my app. For this reason I want to store it in a separate file. So I created mywidget.xml in which

3条回答
  •  离开以前
    2021-01-04 18:42

    Try this:

    mContainerView = (LinearLayout)findViewById(R.id.parentView);    
    LayoutInflater inflater =(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);  
    View myView = inflater.inflate(R.layout.row, null);  
    mContainerView.addView(myView); 
    

    mContainerViewis LinearLayout which contain your EditText and row is your xml filename.

提交回复
热议问题