Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is android studio. I have these five buttons: activity_main.xml < android.support.constraint.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

This is android studio. I have these five buttons:

activity_main.xml

xml version="1.0" encoding="utf-8"?> <android.support.constraint.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"> <Button  android:id="@+id/startgame"  android:layout_width="125dp"  android:layout_height="87dp"  android:text="Start Game"  app:layout_constraintBottom_toBottomOf="parent"  app:layout_constraintEnd_toEndOf="parent"  app:layout_constraintHorizontal_bias="0.5"  app:layout_constraintStart_toStartOf="parent"  app:layout_constraintTop_toBottomOf="@+id/viewscoreboard" /> <Button  android:id="@+id/viewscoreboard"  android:layout_width="125dp"  android:layout_height="87dp"  android:text="View Scoreboard"  app:layout_constraintBottom_toTopOf="@+id/startgame"  app:layout_constraintEnd_toStartOf="@+id/addplayer"  app:layout_constraintHorizontal_bias="0.5"  app:layout_constraintStart_toStartOf="parent"  app:layout_constraintTop_toBottomOf="@+id/selectplayer1" /> <Button  android:id="@+id/addplayer"  android:layout_width="125dp"  android:layout_height="87dp"  android:text="Add Player"  app:layout_constraintBottom_toTopOf="@+id/startgame"  app:layout_constraintEnd_toEndOf="parent"  app:layout_constraintHorizontal_bias="0.5"  app:layout_constraintStart_toEndOf="@+id/viewscoreboard"  app:layout_constraintTop_toBottomOf="@+id/selectplayer2" /> <Button  android:id="@+id/selectplayer2"  android:layout_width="125dp"  android:layout_height="87dp"  android:text="Select Player 2"  app:layout_constraintBottom_toTopOf="@+id/addplayer"  app:layout_constraintEnd_toEndOf="parent"  app:layout_constraintHorizontal_bias="0.5"  app:layout_constraintStart_toEndOf="@+id/selectplayer1"  app:layout_constraintTop_toTopOf="parent" /> <Button  android:id="@+id/selectplayer1"  android:layout_width="125dp"  android:layout_height="87dp"  android:text="Select Player 1"  app:layout_constraintBottom_toTopOf="@+id/viewscoreboard"  app:layout_constraintEnd_toStartOf="@+id/selectplayer2"  app:layout_constraintHorizontal_bias="0.5"  app:layout_constraintStart_toStartOf="parent"  app:layout_constraintTop_toTopOf="parent" /> android.support.constraint.ConstraintLayout>

Here is a class I call GameEmulator:

import android.app.Activity; import android.os.Bundle; import android.widget.TextView; public class GameEmulator extends Activity{ public TextView textview; public TextView textview2; public TextView nameOne; public TextView nameTwo; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.layout); textview = findViewById(R.id.textView); textview2 = findViewById(R.id.textView2); nameOne = findViewById(R.id.name1); nameTwo = findViewById(R.id.name2); } }

with this layout:

layout.xml

xml version="1.0" encoding="utf-8"?> <android.support.constraint.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:id="@+id/relativeLayout"  android:layout_width="match_parent"  android:layout_height="match_parent"  android:orientation="vertical"  tools:context=".GameEmulator"> <TextView  android:id="@+id/textView"  android:layout_width="122dp"  android:layout_height="72dp"  android:layout_marginLeft="28dp"  android:layout_marginStart="28dp"  android:layout_marginTop="68dp"  android:gravity="center"  android:text="Player 1"  android:textSize="24sp"  android:textStyle="bold"  app:layout_constraintBottom_toBottomOf="parent"  app:layout_constraintStart_toStartOf="parent"  app:layout_constraintTop_toTopOf="parent"  app:layout_constraintVertical_bias="0.0" /> <TextView  android:id="@+id/textView2"  android:layout_width="122dp"  android:layout_height="72dp"  android:layout_marginTop="180dp"  android:gravity="center"  android:text="Player 2"  android:textSize="24sp"  android:textStyle="bold"  app:layout_constraintEnd_toEndOf="parent"  app:layout_constraintHorizontal_bias="0.106"  app:layout_constraintStart_toStartOf="parent"  app:layout_constraintTop_toTopOf="parent" /> <TextView  android:id="@+id/name1"  android:layout_width="122dp"  android:layout_height="72dp"  android:layout_marginTop="38dp"  android:gravity="center"  android:text=""  android:textSize="24sp"  android:textStyle="bold"  app:layout_constraintBottom_toBottomOf="parent"  app:layout_constraintEnd_toEndOf="parent"  app:layout_constraintHorizontal_bias="0.5"  app:layout_constraintStart_toEndOf="@+id/textView"  app:layout_constraintTop_toTopOf="parent"  app:layout_constraintVertical_bias="0.074" /> <TextView  android:id="@+id/name2"  android:layout_width="122dp"  android:layout_height="72dp"  android:gravity="center"  android:text=""  android:textSize="24sp"  android:textStyle="bold"  app:layout_constraintBottom_toBottomOf="parent"  app:layout_constraintEnd_toEndOf="parent"  app:layout_constraintStart_toEndOf="@+id/textView2"  app:layout_constraintTop_toTopOf="parent"  app:layout_constraintVertical_bias="0.41" /> <Button  android:id="@+id/button8"  android:layout_width="104dp"  android:layout_height="63dp"  app:layout_constraintBottom_toBottomOf="parent"  app:layout_constraintEnd_toEndOf="parent"  app:layout_constraintHorizontal_bias="0.5"  app:layout_constraintStart_toStartOf="parent"  app:layout_constraintTop_toBottomOf="@+id/button6"  android:text="It's a tie!"/> <Button  android:id="@+id/button6"  android:layout_width="104dp"  android:layout_height="63dp"  app:layout_constraintBottom_toTopOf="@+id/button8"  app:layout_constraintEnd_toEndOf="parent"  app:layout_constraintHorizontal_bias="0.5"  app:layout_constraintStart_toEndOf="@+id/button7"  app:layout_constraintTop_toBottomOf="@+id/name2"  android:text="Player 2 Wins!"/> <Button  android:id="@+id/button7"  android:layout_width="104dp"  android:layout_height="63dp"  app:layout_constraintBottom_toTopOf="@+id/button8"  app:layout_constraintEnd_toStartOf="@+id/button6"  app:layout_constraintHorizontal_bias="0.5"  app:layout_constraintStart_toStartOf="parent"  app:layout_constraintTop_toBottomOf="@+id/textView2"  android:text="Player 1 Wins!"/> android.support.constraint.ConstraintLayout>

How do I get the buttons to open up a new activity. I need the button gamestart to open the layout view connected to GameEmulator which is layout.xml. I keep getting errors so I need to see a way to make this work.

 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

1. Identify six different types of history.

Answered: 1 week ago

Question

2. Define the grand narrative.

Answered: 1 week ago

Question

4. Describe the role of narratives in constructing history.

Answered: 1 week ago