Question

Q1 ) Write a program to change the activities and update the UI interface by pressing...

Q1 ) Write a program to change the activities and update the UI interface by pressing down the buttons next and previous?

USING ANDROID STUDIO JAVA LANGUAGE

0 0
Add a comment Improve this question Transcribed image text
Answer #1

for jump from one activity to another activity we use, Intent class .

intent are two types , 1- implicit intent 2- explicit intent,,

here i am using the explicit intent ... here the code----

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="272dp"
        android:layout_marginEnd="76dp"
        android:layout_marginBottom="144dp"
        android:text="This is First Actity.."
        android:textSize="30dp"
        app:layout_constraintBottom_toTopOf="@+id/button"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="110dp"
        android:layout_marginBottom="344dp"
        android:text="go to second activity"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

main.java

package com.e.changeactivity;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button nxt;
        nxt=(Button)findViewById(R.id.button);

        nxt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(MainActivity.this,Main2Activity.class);
                startActivity(intent);
            }
        });
    }
}

activity_second.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
    tools:context=".Main2Activity">
 <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="153dp"
        android:layout_marginTop="274dp"
        android:layout_marginEnd="199dp"
        android:layout_marginBottom="438dp"
        android:text="This is second activity"
        android:textSize="36sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.422"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
  <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="84dp"
        android:text="go to first activity"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.498"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView"
        app:layout_constraintVertical_bias="0.0" />
</androidx.constraintlayout.widget.ConstraintLayout>

mainsecond.java--

package com.e.changeactivity;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class Main2Activity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        Button previous=(Button)findViewById(R.id.button3);
        previous.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(Main2Activity.this,MainActivity.class);
                startActivity(intent);
            }
        });
    }
}
Add a comment
Know the answer?
Add Answer to:
Q1 ) Write a program to change the activities and update the UI interface by pressing...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • *15.7 (Change color using a mouse) Write a program that displays the color of a circle...

    *15.7 (Change color using a mouse) Write a program that displays the color of a circle as red when the mouse button is pressed and as blue when the mouse button is released. Please complete using Java language

  • Using IntelliJ create a Java GUI window program that contains all the interface components covered in...

    Using IntelliJ create a Java GUI window program that contains all the interface components covered in the lecture. JPanel - Green with Yellow text JButton - four buttons JLabel - four labels JTextField - three text fields JPasswordField - one is fine JCheckBox - four different birds JComboBox - four different flowers JList - three different bikes JSlider - goes up to max 100 at 10 increments JMenu - contains File with pull down options-> save -> save all

  • Write a program that reverses a text file by using a stack. The user interface must...

    Write a program that reverses a text file by using a stack. The user interface must consist of 2 list boxes and 3 buttons. The 3 buttons are: Read - reads the text file into list box 1. Reverse - reverses the items in list box 1 by pushing them onto stack 1, then popping them from stack 1 (in the reverse order) and adding them to list box 2. Write - writes the contents of list box 2 to...

  • Q1. Write a program in Java         a. Create 2 separate arrays, of user defined values,...

    Q1. Write a program in Java         a. Create 2 separate arrays, of user defined values, of same size         b. Add these 2 arrays. ........................................................................................................................... Q2. Write a program in java (using loop) input any10 numbers from user and store in an array. Check whether each of array element is positive, negative, zero, odd or even number. ............................................................................................................................ Q3. Write a program in Java to display first 10 natural numbers. Find the sum of only odd numbers. .............................................................................................................................. Q4....

  • WRITE a program in JAVA using GRAPHICAL USER INTERFACE to make fruit and vegetable display panel with a toggle switch.(m...

    WRITE a program in JAVA using GRAPHICAL USER INTERFACE to make fruit and vegetable display panel with a toggle switch.(make two displays panel 1 for fruit and the other for vegetables , if we press the toggle switch then the 1st panel will show and if we again press the switch then the 1st will hide and other will show) and vice versa.

  • java programming language Problem3 (1.5 points). Write a Java program to input electricity unit charges and...

    java programming language Problem3 (1.5 points). Write a Java program to input electricity unit charges and calculate total electricity bill according to the given condition: For first 50 units Rs. 0.50/unit For next 100 units Rs. 0.75/unit For next 100 units Rs. 1.20/unit For unit above 250 Rs. 1.50/unit An additional surcharge of 20% is added to the bill Problem4 (1 points). Write a Java program to inputs weekday number and prints the weekday name using switch.

  • Use C++ language. Write a program that gives and takes advice on program writing. The program...

    Use C++ language. Write a program that gives and takes advice on program writing. The program starts by writing a piece of advice to the screen and asking the user to type in a different piece of advice. The program then ends. The next person to run the program receives the advice given by the person who last ran the program. The advice is kept in a file, and the contents of the file change after each run of the...

  • GUI bouncing shapes program use this interface the out put of the program should be a jFr...

    GUI bouncing shapes program use this interface the out put of the program should be a jFrame with three buttons: “add triangle”, “add square” and “add circle” and a blank screen. when the user clicks any of these buttons the corresponding shape appears and starts bouncing around the screen. the shape of these shaoes and randomized and anytime the user clicks the button you should be able to keeping adding shapes on the screen while the previosus shape is bouncing...

  • Write a scripting interface that accepts the following commands:    The program must run a continuous...

    Write a scripting interface that accepts the following commands:    The program must run a continuous loop and not shut down after    each operation -- that is, continuously asks for input until "exit"    is typed. Specification:    Run as: java Calc    This throws up a prompt which accepts the following syntax:     PROMPT>> <number1> + <number2>     PROMPT>> <number1> - <number2>     PROMPT>> <number1> * <number2>     PROMPT>> <number1> / <number2>     PROMPT>> <number1> % <number2>    ...

  • Creating a Shell Interface Using Java This project consists of modifying a Java program so that...

    Creating a Shell Interface Using Java This project consists of modifying a Java program so that it serves as a shell interface that accepts user commands and then executes each command in a separate process external to the Java virtual machine. Overview A shell interface provides the user with a prompt, after which the user enters the next command. The example below illustrates the prompt jsh> and the user’s next command: cat Prog.java. This command displays the file Prog.java on...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT