How to inflate a class on Android?

5

I needed to inflate a form on a tab, I always do the form in xml, but this time I did via code, does anyone know how I display my class instead of xml in a FragmentTab ?

Code to inflate xml to View :

if(this.getTag() == "formulario3"){
    return inflater.inflate(R.layout.formulario3, container, false);
}
    
asked by anonymous 23.06.2015 / 16:38

1 answer

2

You have to inflate fragment to your layout first, using LayoutInflater to map your Fragment .

Example:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View fragmentView = inflater.inflate(R.layout.formulario3, container, false);
    TextView text = (TextView) fragmentView.findViewById(R.id.fragmentExemploTxt);
    mTextNoResult = (TextView) fragmentView.findViewById(R.id.text_resultado);
    return fragmentView;
}
    
03.07.2015 / 18:32