Q1 Using Android Studio do the following a Run Second Activi

Q1) Using Android Studio do the following:

a) Run Second Activity Demo and Basic Components, use bitbucket.org to get files.

b) Build APK files.

c) Modify and/or create java code in the MainActivity.java file so that the interface widget implements some “Action” when the application runs. For example, you might create a simple button, that, when clicked, changes color. Or, you might have a text field that when a button is clicked, the text changes in some way (i.e., is stored, is deleted, etc…). Also, be sure to study and understand how the widgets that you create are described in the activity_main.xml file (This step has to be implemented effectively).

d) Attach screenshots of the following project elements and upload

1.Test of application

2. Activity_main.xml (code and design)

3. MainActivity.java (code)

4. Other screenshots as necessary

Solution

<?xml version=\"1.0\" encoding=\"utf-8\"?>
<RelativeLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"
    xmlns:tools=\"http://schemas.android.com/tools\"
    android:layout_width=\"match_parent\"
    android:layout_height=\"match_parent\"
    android:paddingBottom=\"@dimen/activity_vertical_margin\"
    android:paddingLeft=\"@dimen/activity_horizontal_margin\"
    android:paddingRight=\"@dimen/activity_horizontal_margin\"
    android:paddingTop=\"@dimen/activity_vertical_margin\"
    android:background=\"@drawable/splash\"
    tools:context=\"net.simplifiedcoding.simplegame.MainActivity\">

    <ImageButton
        android:id=\"@+id/buttonPlay\"
        android:background=\"@drawable/playnow\"
        android:layout_width=\"wrap_content\"
        android:layout_height=\"wrap_content\"
        android:layout_above=\"@+id/buttonScore\"
        android:layout_centerHorizontal=\"true\" />

    <ImageButton
        android:id=\"@+id/buttonScore\"
        android:background=\"@drawable/highscore\"
        android:layout_width=\"wrap_content\"
        android:layout_height=\"wrap_content\"
        android:layout_alignParentBottom=\"true\"
        android:layout_centerHorizontal=\"true\" />

</RelativeLayout>

When we tap the Play Now button our Game Activity will start.
Now come inside MainActivity.javaand write the following code.

MainActivity.java
Java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package net.simplifiedcoding.simplegame;

import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.media.Image;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{

    //image button
    private ImageButton buttonPlay;

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

        //setting the orientation to landscape
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

        //getting the button
        buttonPlay = (ImageButton) findViewById(R.id.buttonPlay);

        //adding a click listener
        buttonPlay.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        
        //starting game activity
        startActivity(new Intent(this, GameActivity.class));
    }

Q1) Using Android Studio do the following: a) Run Second Activity Demo and Basic Components, use bitbucket.org to get files. b) Build APK files. c) Modify and/o
Q1) Using Android Studio do the following: a) Run Second Activity Demo and Basic Components, use bitbucket.org to get files. b) Build APK files. c) Modify and/o
Q1) Using Android Studio do the following: a) Run Second Activity Demo and Basic Components, use bitbucket.org to get files. b) Build APK files. c) Modify and/o

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site