dody.ac
dody.ac

Reputation: 77

How to Remove Cardview?

Im begginer for android studio, I have cardview at my home acvity, thats cardview just give information if email still not verified. And email has been verified, cardview must not show at home activity My question is, how we can remove cardview from home activity if email has been verified?

Upvotes: 0

Views: 181

Answers (1)

Jesse Lima
Jesse Lima

Reputation: 386

I can not see exactly how your code works. But I can give you an idea of how you can get what you want.

You remove any view from the layout or just make them invisible. Create a reference for the CardView you want to hide in your Activity. Then apply the setVisibility(View.GONE) in the object you want to hide.

public class MainActivity extends AppCompatActivity {

    private CardView cardView;

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

        cardView = findViewById(R.id.your_card_view_id_in_the_xml);

   }

   // then you hide the cardView in any method you want.
   private void anyMethod() {
    if (someCondition) {
      cardView.setVisibility(View.GONE);
   }


   /* 
      Note that if you use View.GONE the cardView will disappear from the UI.
      If you want to keep the empty space where the cardView you can do 
      it using cardView.setVisibility(View.INVISIBLE). And if you want to show 
      the card again just use cardView.setVisibility(View.VISIBLE)
   */


}

When posting questions here try to paste some code to help people to understand your problem better in a better way ok? Good practice! Happy coding!

Upvotes: 1

Related Questions