How to inflate a class on Android?

Asked

Viewed 260 times

5

I needed to inflate a form into a tab, always make the form in xml, but this time I did it via code, someone knows how to display my class instead of xml in a FragmentTab?

Code to inflate an xml in a View:

if(this.getTag() == "formulario3"){
    return inflater.inflate(R.layout.formulario3, container, false);
}
  • Friend, I don’t understand your question! Instead of creating the xml, you created the elements by programming it in a Fragment?

1 answer

2

You have to inflate the fragment for your layout first, using the 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;
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.