Nogg
Nogg

Reputation: 337

How to make android checkbox disable something in a layout?

Right now I have 4 checkboxes and I need to check if they're un-clicked. If they are then the next activity's layout needs to change. Right now I have the checkboxes on activity 1. Activity two gets a string variable from activity 1 and parses it into an int and checks if it was handed a zero or 1. Now on activity 2 there is a button to add things to that activity which pulls up a popup window.

public void newUserInput(View view){
        LayoutInflater inflater = (LayoutInflater)
                Launch.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        PopupWindow pw = new PopupWindow(inflater.inflate(R.layout.popup_layout,null,false),300,400,true);

        pw.showAtLocation(findViewById(R.id.button1), Gravity.CENTER, 0, 0);

So... the popup window that pops up is what needs to be affected by what was clicked/unclicked in activity 1. My idea was to just check if it's zero and if it is then hide the text and text box for that entry. I'm just not too sure if I can do that? Also my popup window is absolute, which I figure if I hide one the others won't get pushed up to make it look cleaner, right?

Upvotes: 0

Views: 569

Answers (2)

japino
japino

Reputation: 134

You can definitely hide items in the layout based on your options. I'm not sure what your variables are called that hold the options but you could do something like the following.

public void newUserInput(View view) {
    LayoutInflater inflater = (LayoutInflater)
        Launch.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    View inflatedView = inflater.inflate(R.layout.popup_layout,null,false);

    if (myOption == 0) {
        TextView tv = (TextView) inflatedView.findViewById(R.id.my_text_view);
        tv.setVisibility(TextView.INVISIBLE);
    }

    PopupWindow pw = new PopupWindow(inflatedView,300,400,true);

    pw.showAtLocation(findViewById(R.id.button1), Gravity.CENTER, 0, 0);
}

It's important to note that TextView.INVISIBLE will only make the TextView invisible... it will not remove it from the layout, so your styling should look the same as if it were visible. If you wanted to remove the TextView from the layout completely then you can use TextView.GONE.

Upvotes: 3

CSmith
CSmith

Reputation: 13458

A couple ideas:

Activity 2 can conditionally load different layouts. OR, you can use View.setVisibility(View.GONE); to hide a view (or ViewGroup) from your layout.

So if you have for example a bunch of RelativeLayouts (layout1, layout2, layout3) that are stacked, if you do layout2.setVisibility(View.GONE), the layout will draw as if it doesn't exist.

Upvotes: 0

Related Questions