0% found this document useful (0 votes)
7 views

Ex.no.4 (Usage of Image Button)

The document outlines the steps to develop an Android application that utilizes an Image Button. It includes a procedure for creating the project, designing the layout, and implementing the functionality to display a Toast message when the button is clicked. The provided code demonstrates the implementation in the MainActivity.java file, confirming successful creation and testing of the application.

Uploaded by

raguljo1421
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)
7 views

Ex.no.4 (Usage of Image Button)

The document outlines the steps to develop an Android application that utilizes an Image Button. It includes a procedure for creating the project, designing the layout, and implementing the functionality to display a Toast message when the button is clicked. The provided code demonstrates the implementation in the MainActivity.java file, confirming successful creation and testing of the application.

Uploaded by

raguljo1421
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

Ex.No.

4: Develop an application that uses the Image Button


Aim:
To develop an application that uses the Image Button
Procedure:
Step 1: Create new project
Step 2: Click xml file (activity_main.xml)
Step 3: Click design option and design your application using (TextView, ImageButton)

Step 4: Copy and Paste the desired image in the app/res/drawable location

Step 5: Now, open up the activity java file (MainActivity.java).


Step 6: Write the code for image button.

Step 7: Add the click listener to the image button.


Step 8: When that image button has been clicked, “Image Button is clicked” message will be
displayed using Toast.

Step 9: End.
Code:
MainActivity.java
package com.example.useimagebutton;
import androidx.appcompat.app.AppCompatActivity;
import android.widget.ImageButton;
import android.widget.Toast;
import android.view.View;
import android.view.View.OnClickListener;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {


ImageButton imageButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListenerOnButton();
}
public void addListenerOnButton() {
imageButton = (ImageButton) findViewById(R.id.imageButton);
imageButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Toast.makeText(MainActivity.this,
"ImageButton is clicked!", Toast.LENGTH_SHORT).show();
}
});
} }
Output:

Result:
This Mobile Application has been created and tested successfully.

You might also like