Showing posts with label Class 7. Show all posts
Showing posts with label Class 7. Show all posts

Class 7 (Visibility )

 Visivility


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity"
android:background="#AACFEC"
android:layout_margin="20sp"
>

<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="300dp"
android:src="@drawable/tshart"
android:visibility="invisible"
/>


<Button
android:id="@+id/bShow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Show Image"
/>

<Button
android:id="@+id/bGone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Go Away"
/>


</LinearLayout>
Java
package com.rakibshah.testblog;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

ImageView image;
Button bShow,bGone;

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

image = findViewById(R.id.image);
bShow = findViewById(R.id.bShow);
bGone = findViewById(R.id.bGone);



bShow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

image.setVisibility(View.VISIBLE);

}
});

bGone.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

image.setVisibility(View.GONE);

}
});


}
}