How to reuse a layout?

Asked

Viewed 113 times

1

I want to create a screen with editorial menu, as I do to "reuse" a layout to have multiple essays and fewer layout files (xml).

  • I didn’t get it right, I would have to create a custom Adapter with a list ?

  • From what I understand your question is this, but I may have misunderstood

1 answer

1


You can have a Fragment or a Activity with a layout fixed, receiving different parameters so that you can inflate the fields the way you want depending on the received parameters. By doing this you can hide fields that you do not use in an X case but use in the Y case, using the function .setVisibility

Ex:

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_padrao);

        Textview txtNotaUm = (TextView)findViewById(R.id.txtNotaUm);
        Textview txtNotaDois = (TextView)findViewById(R.id.txtNotaDois);

        Boolean tipoUm = getIntent().getExtras().getBoolean("tipoUm");

        if(tipoUm){               
           txtNotaUm.setVisibility(View.VISIBLE);
           txtNotaDois.setVisibility(View.GONE);
        }
        else{
           txtNotaUm.setVisibility(View.GONE);
           txtNotaDois.setVisibility(View.VISIBLE);
        }    
    }

Browser other questions tagged

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