1 /*
2  * Copyright (C) 2007 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.example.android.apis.view;
18 
19 // Need the following import to get access to the app resources, since this
20 // class is in a sub-package.
21 import com.example.android.apis.R;
22 
23 import android.app.Activity;
24 import android.os.Bundle;
25 import android.view.View;
26 import android.view.View.OnClickListener;
27 import android.widget.Button;
28 
29 
30 /**
31  * Demonstrates making a view VISIBLE, INVISIBLE and GONE
32  *
33  */
34 public class Visibility1 extends Activity {
35 
36     private View mVictim;
37 
38     @Override
onCreate(Bundle savedInstanceState)39     protected void onCreate(Bundle savedInstanceState) {
40         super.onCreate(savedInstanceState);
41         setContentView(R.layout.visibility_1);
42 
43         // Find the view whose visibility will change
44         mVictim = findViewById(R.id.victim);
45 
46         // Find our buttons
47         Button visibleButton = (Button) findViewById(R.id.vis);
48         Button invisibleButton = (Button) findViewById(R.id.invis);
49         Button goneButton = (Button) findViewById(R.id.gone);
50 
51         // Wire each button to a click listener
52         visibleButton.setOnClickListener(mVisibleListener);
53         invisibleButton.setOnClickListener(mInvisibleListener);
54         goneButton.setOnClickListener(mGoneListener);
55     }
56 
57     OnClickListener mVisibleListener = new OnClickListener() {
58         public void onClick(View v) {
59             mVictim.setVisibility(View.VISIBLE);
60         }
61     };
62 
63     OnClickListener mInvisibleListener = new OnClickListener() {
64         public void onClick(View v) {
65             mVictim.setVisibility(View.INVISIBLE);
66         }
67     };
68 
69     OnClickListener mGoneListener = new OnClickListener() {
70         public void onClick(View v) {
71             mVictim.setVisibility(View.GONE);
72         }
73     };
74 }
75