Can you inflate a class?

2

There are many methods that you inflate a layout.xml but I need to inflate a class inside a tab, does anyone know what I can do? I'm in the choke here. To inflate layout.xml use this code:

if(this.getTag() == "formulario3"){
   return inflater.inflate(R.layout.formulario3, container, false);
}

But I created a dynamic form only by Java code and I'm not able to inflate.

    
asked by anonymous 24.06.2015 / 23:36

1 answer

0

daniel12345smith , assuming the class stores objects / properties of type View . So instead of "inflating" (which is a unique option to work with xml ), you can call methods of this class that insert into the Context you want these views related to this class.

Example

PrincipalActivity.java

@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_principal);

    Contatos.carregaContatos(PrincipalActivity.this);
}

Contatos.java

public class Contatos
{

    public static void carregaContatos(Activity activity)
    {
        // declara TextView
        // note que "activity" agora pode procurar uma view da activity PrincipalActivity.java 
        TextView textView = new TextView(); // ou "this.minhaTextView", whatever

        // codigo que insere uma View guardada e gerida por esta classe "Contatos"
        // note que "activity" agora pode procurar uma view da activity PrincipalActivity.java 
        LinearLayout linearLayout = activity.findViewById(R.id.info); 
        linearLayout.addView(textView);

    }

}

And so on. The idea is to keep the logic logic and business logic separate (unfortunately Android follows a default View-Controller) and we have to turn around as we can.

    
24.06.2015 / 23:55