2 Replies - 626 Views - Last Post: 25 April 2016 - 06:43 AM

#1 [email protected]   User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 96
  • Joined: 31-January 16

How to Go to New Screen/Page in Android Studio?

Posted 24 April 2016 - 07:31 PM

Hello < Dream.in.code >.. I have a quick question regarding android studio.

So First Of all I am COMPLETELY new to this thing so don't get me wrong if i make a mistake.

So what I am doing is that I have created a title screen for my app called "Canada Quiz". And below the title I have a "Start" Button. And what I done so far is I have attached a code that would do something like this: So once a Start Button is clicked it would hide it. Now my Question.

How would I make it so That once Clicked it should hide the Start Button and show the Question and a TRUE and FALSE button. All I have is this. I just want the Questions the appear as soon as the person taps the Start Button. And in My Content_Main.xml i have a phone as a model witch displays the start button and the canada quiz. So Please Healpp Me Out as soon as POSSIBLE>>>

ThankYOU>>>>>>><<<<<<<<<<<

package com.example.nilesh.myapplication;

import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

    private Button startButton;
    private Button trueButton;
    private Button falseButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        startButton = (Button) findViewById(R.id.startButton);

        ArrayList <String> questions = new ArrayList<String>();

        String firstQue = " Is Canada Located in North America? ";
        String secondQue = " Is Ontario the Largest provice in Canada? ";
        String thridQue = " Is Toronto the Largest City in Canada? ";
        String fourQue = " Canada has 3 professional Basketball Teams. ";
        String fiveQue = " Canada has 11 Provinces and 3 Territories. ";
        String sixQue = " Justin Trudeau is not Canada's Prime Minister. ";

        final String [] allQuestions = {firstQue,secondQue,thridQue,fourQue,fiveQue,sixQue};


        startButton.setonclickListener(new View.onclickListener() {
            public void onclick (View v) {
                startButton.setVisibility(View.INVISIBLE);
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    public Button getTrueButton() {
        return trueButton;
    }

    public void setTrueButton(Button trueButton) {
        this.trueButton = trueButton;
    }

    public Button getFalseButton() {
        return falseButton;
    }

    public void setFalseButton(Button falseButton) {
        this.falseButton = falseButton;
    }
}


**Note** I cannot see the TRUE BUTTON and FALSE BUTTON the content_main.xml file....

This post has been edited by [email protected]: 24 April 2016 - 08:08 PM


Is This A Good Question/Topic? 0
  • +

Replies To: How to Go to New Screen/Page in Android Studio?

#2 ChrisNt   User is offline

  • cute bug

Reputation: 262
  • View blog
  • Posts: 896
  • Joined: 31-July 13

Re: How to Go to New Screen/Page in Android Studio?

Posted 25 April 2016 - 01:43 AM

Quote

"I cannot see the TRUE BUTTON and FALSE BUTTON the content_main.xml file.... "

Why ?

Basically you have to play with the visibility of you View .For example you can set the attribute of a View in your xml file as android:visibility="gone" to be hidden .
<Button
    android:id="@+id/example_button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    ...
    android:visibility="gone"
    />



then when the button is clicked you can call method setVisibility(View.VISIBLE) to be visible.

Button exampleButton = (Button)findViewById(R.id.exampleButton);

  exampleButton.setonclickListener(new View.onclickListener() {
             public void onclick(View v) {
                 button.setVisibility(View.VISIBLE);
   }
  });





Another way would be to use Fragments, when the button is clicked you would add your fragment in your main activity.

This post has been edited by ChrisNt: 25 April 2016 - 01:46 AM

Was This Post Helpful? 1
  • +
  • -

#3 Dankwansere   User is offline

  • D.I.C Regular

Reputation: 82
  • View blog
  • Posts: 256
  • Joined: 09-November 09

Re: How to Go to New Screen/Page in Android Studio?

Posted 25 April 2016 - 06:43 AM

You can use "Intents" to go to different screens(fragments or activities), you can create the questions on a different screen(eg. fragment or activity) then add an intent to call the new screen from the start button on your first screen. Please take a look at these android documentation on intents.

Android Intent API Guide

Android Intent API reference
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1