Show/hide views with checkbox

I want to show or hide some elements (textviews and edittexts) with checkbox. I set their visibility to gone in layout file. Showing them when user checks the box works, but the when user unchecks it, they don't hide. (android 1.5 and 1.6)

My code:

cb=(CheckBox)findViewById(; cb.setOnClickListener(new OnClickListener() { // checkbox listener public void onClick(View v) { // Perform action on clicks, depending on whether it's now checked if (((CheckBox) v).isChecked()) { tv1.setVisibility(0); //visible==0 et3.setVisibility(0); } else if (((CheckBox) v).isChecked() == false) { tv1.setVisibility(2); //gone=2 et3.setVisibility(2); } } });

-------------Problems Reply------------

Don't use magic numbers like 0 or 2. Use GONE, VISIBLE or INVISIBLE instead: Android Developers site

Category:java Views:2 Time:2010-04-24
Tags: java android

Related post

  • hide/view a group of markers with gomap-plugin 2012-02-08

    I like to hide/view a group of markers in a map with the plugin gomap() like here: for now I realized it with hiding/viewing only one marker: $(function() { $("#map_canvas").goMap({ latitude: 46.

  • How to Hide/view the portlets in liferay Portal? 2010-09-27

    I m developing portlets on liferay portal using icefaces, i want to hide/view the portlet programmaticaly from an action written in my managed bean. so please help me ASAP? Thanks in advance... --------------Solutions------------- You can invoke the

  • How to create a tree view with checkboxes in Python 2011-02-24

    I've been using Tkinter and Tix to write a small program. I'm at a point where I need a tree view with checkboxes (checkbuttons) so I can select items from the tree view. Is there an easy way to do this? I've been looking at ttk.Treeview () and it lo

  • How do I create a tree view (with checkbox) inside a combo box - PyQt 2011-03-07

    I'm using PYQT for developing an application. my requirement is to insert a tree view with checkbox inside a combobox items. I would like to know how to achieve this? I have the following code but this does not work. class CheckboxInsideListbox(QWidg

  • RenderPartial Views with CheckBoxes. 2012-03-08

    For each each item available i render a partial view, in the partial view I have a checkbox. The purpose is so that the the user can select multiple items at once, then when they hit delete all the items selected will be deleted. Checkbox in my parti

  • Jquery: setting div hide / show with checkbox checking initial state 2012-04-03

    I am trying to hide divs when the associated checkbox is checked. To get it to work with the initial jstate of the checkbox I added triggerHandler('click'). This works fine for the first checkbox but not for any others. Any suggestions? Fiddle here:

  • Expandable view on checkbox click Android 2012-04-09

    I'm looking for a way to expand a view when someone clicks on a checkbox. If checkbox = true, the view expands. if false the view folds. The basic idea is that I have a class newPokerGame and if the game is a tournament (the checkbox) some view will

  • phpBB help: Hide 'views' and 'replies' column on the forum view page 2009-07-16

    I am new to PHP. I am trying to hide total number of 'Views' and 'Replies' column on the forum view page. I am not sure what all changes would be required. My working environment consists of phpBB v3.0.0 and MySQL v4.1.1. Would appreciate any help or

  • how to hide textareas if checkboxes not checked - JQuery 2010-06-21

    I'm trying to use jQuery to look at a form and for each of the checkboxes 'if checked' then show a div containing a textarea. Each div for checkbox id 'checkbiox_foo' is id 'checkbox_foo_reasons' I'm a total noob at jquery so I've got this far but I

  • SegmentedControll in navigation bar hides view.title 2010-07-08

    I'm using a segmented control in the navigationbar in a tabbarcontroller app. The problem is that after adding the segmented control to the navigation bar the title of my view disappears form the tabbarcontroller. How do i work around this problem? -

  • hide text when checkbox is unchecked using jquery 2010-07-22

    the checkboxes are checked by default. if unchecked they should hide the text. how do i hide or show the text in jquery? html: <div class="check"> <p><input type="checkbox" value="Name" id="name" checked /> <label for="name">N

  • How to hide an HTML checkbox but still show its label 2010-11-08

    I'm new to jQuery and I have been trying to figure out how to use the jQuery-ui Selectable component as an alternative to a set of checkboxes. I think I could get it to work if I can find a way to hide the checkb

  • How to hide view source 2010-11-17

    Could some one please help me out to hide a view source option of a web page in dot net ? --------------Solutions------------- You can't, it is an option of the browser. The best you can do is obfuscate it. Back in the Geocities era of the internet i

  • How do I easily show/hide views in Griffon 2010-12-05

    First: I'm shocked that I have to ask this question. Nowhere in the docs is it explained how the new "WindowManager" should be used... I've been hacking around some hours around this and I still dont have an satistactionary way of doing something as

  • How to show if something is checked in a view using checkboxes? 2011-02-10

    I'm working on a test app where users can create ideas. I'm trying to give them the option of selecting if the idea will be recurring, using a checkbox (see below): <div class= "field"> <%= check_box_tag(:recur) %> <%= label_tag(:recur

  • View like checkbox without the check? 2011-07-17

    I'm wondering if there is a view like the checkbox, but without the checkbox part? I just want a nice clean list of items with just the text portion showing, still allowing click events. --------------Solutions------------- Create a ListView in your

  • Android: Grid view with clickable grid items and nested views (buttons, checkboxes) 2011-09-12

    Basically, I would like to implement a GridView wherein the items themselves are clickable, but within the GridView are clickable Buttons and Checkboxes. Here's a sample layout: Gridview ----------------------------------------- |[ImageView] |[ImageV

  • hide view parameters in the URL 2011-12-23

    We are using JSF 2.0. We have to pass in view parameters from one page to another page as the pages are view scoped. We are getting the values in the params but I would like to know if there is there a way to hide the parameters in the URL? `public S

  • hide view in interface builder when there are multiple views 2012-02-09

    This is probably a dumb question, but I can't seem to figure it out. In IB, if I have two UIViews, that are subviews of the main UIViewController.view that I basically show and hide depending on the user's input, is there a way to hide one of the vie

Copyright (C), All Rights Reserved.

processed in 0.080 (s). 11 q(s)