0% found this document useful (0 votes)
23 views3 pages

Assignment 9

The document discusses creating an Android application with an ImageButton, two ToggleButtons and a Button. It includes the XML layout and Java code for the MainActivity class to handle user interactions with the buttons.

Uploaded by

Swayam Mehta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views3 pages

Assignment 9

The document discusses creating an Android application with an ImageButton, two ToggleButtons and a Button. It includes the XML layout and Java code for the MainActivity class to handle user interactions with the buttons.

Uploaded by

Swayam Mehta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Assignment 9

IMAGE BUTTON
<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:layout_editor_absoluteX="5dp"
tools:layout_editor_absoluteY="4dp">

<ImageButton
android:id="@+id/imageButton"
android:layout_width="130dp"
android:layout_height="120dp"
android:layout_marginLeft="7dp"
android:layout_marginTop="1dp"
android:layout_marginBottom="10dp"
android:layout_marginRight="250dp"
android:scaleType="centerCrop"
android:src="@drawable/insta" />
</LinearLayout>

TOGGLE AND BUTTON

<?xml version="1.0" encoding="utf-8"?>


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<ToggleButton
android:id="@+id/toggle1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:layout_marginTop="120dp"
android:checked="true"
android:textOff="OFF"
android:textOn="ON"/>
<ToggleButton
android:id="@+id/toggle2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="200dp"
android:layout_marginTop="120dp"
android:checked="false"
android:textOff="OFF"
android:textOn="ON"/>

<Button
android:id="@+id/button"
android:layout_width="120dp"
android:layout_height="60dp"
android:layout_marginLeft="145dp"
android:layout_marginTop="200dp"

android:text="Submit" />
</RelativeLayout>

Mainactivity.java

package com.example.myapplication;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.ToggleButton;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;

public class MainActivity extends AppCompatActivity {

private ToggleButton toggleButton1, toggleButton2;


private Button submitButton;

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

toggleButton1 = findViewById(R.id.toggle1);
toggleButton2 = findViewById(R.id.toggle2);
submitButton = findViewById(R.id.button);

// Set onClickListener for the submit button


submitButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// Handle button click event here
// You can add your code to perform some action on button click
}
});

// Set onCheckedChangeListener for toggleButton1


toggleButton1.setOnCheckedChangeListener(new
CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean
isChecked) {
// Handle toggleButton1 state change event here
if (isChecked) {
// ToggleButton1 is ON
// You can add your code for ON state
} else {
// ToggleButton1 is OFF
// You can add your code for OFF state
}
}
});

// Set onCheckedChangeListener for toggleButton2


toggleButton2.setOnCheckedChangeListener(new
CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean
isChecked) {
// Handle toggleButton2 state change event here
if (isChecked) {
// ToggleButton2 is ON
// You can add your code for ON state
} else {
// ToggleButton2 is OFF
// You can add your code for OFF state
}
}
});
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy