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.