如何显示我的调查问卷并根据该Android应用程序决定做什么

时间:2018-03-24 16:22:57

标签: java android

我正在开发Android工作室中的应用程序,我想要它做的是它应该询问用户你想要听音乐或观看视频后他们决定他们的心情。问题是当我点击心情时,它直接进入视频,当我点击后退按钮时,它会询问他们是否喜欢音乐或视频。所以它需要反过来。我正在Android Studios工作。我将在下面粘贴代码。

这是MainActivity.java

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



    Button button0 = (Button) findViewById(R.id.HappyButton);
    Button button1 = (Button) findViewById(R.id.SadButton);
    Button button2 = (Button) findViewById(R.id.MellowButton);
    Button button3 = (Button) findViewById(R.id.MotivatedButton);
    Button button4 = (Button) findViewById(R.id.AngryButton);


    button0.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            Intent myintent = new Intent(MainActivity.this,theOptionsPage.class);
            startActivity(myintent);
            openHappy();
        }
    });

    button1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
        openSad();

        }


    });

    button2.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            openMello();
        }
    });

    button3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            openMotivated();
        }
    });

    button4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            openAngry();
        }
    });


}

    public void showMe(View v){
       String button_text;
       button_text = ((Button) v).getText().toString();
       if(button_text.equals("HAPPY")){
           Intent intent = new Intent(this,theOptionsPage.class);
           startActivity(intent);
        }
    }



                @Override
                public void onClick(View view) {

        }

        public void openHappy(){
        Intent intent = new Intent(this,YoutubeHappy.class);
        startActivity(intent);
        }

        public void openSad(){
            Intent sadintent = new Intent(this,YoutubeSad.class);
            startActivity(sadintent);
        }

        public void openMello(){
            Intent mellowintent = new Intent(this,YoutubeMellow.class);
            startActivity(mellowintent);

        }
        public void openMotivated(){
            Intent motivatedintent = new Intent(this,YoutubeMotivated.class);
            startActivity(motivatedintent);
        }
        public void openAngry(){
            Intent angryintent = new Intent(this,YoutubeAngry.class);{
                startActivity(angryintent);
            }
        }




    }

这是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="com.code.mohamedali.hackathon2018.MainActivity">

<Button
    android:id="@+id/HappyButton"
    android:layout_width="141dp"
    android:layout_height="75dp"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="32dp"
    android:text="HAPPY"
    android:onClick="showMe"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/FeelingView" />

<Button
    android:id="@+id/SadButton"
    android:layout_width="141dp"
    android:layout_height="75dp"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:text="SAD"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/HappyButton" />

<Button
    android:id="@+id/AngryButton"
    android:layout_width="141dp"
    android:layout_height="75dp"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:text="ANGRY"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/SadButton" />

<Button
    android:id="@+id/MotivatedButton"
    android:layout_width="141dp"
    android:layout_height="75dp"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:text="MOTIVATED"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/AngryButton" />

<Button
    android:id="@+id/MellowButton"
    android:layout_width="141dp"
    android:layout_height="75dp"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="12dp"
    android:text="MELLOW"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.513"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/MotivatedButton" />

<TextView
    android:id="@+id/FeelingView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:text="How Are You Feeling Today?"
    android:textAlignment="center"
    android:textSize="30sp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

以下是OptionsPage CodeXML

public class theOptionsPage extends AppCompatActivity {



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

    Button button1 = (Button) findViewById(R.id.MusicButton);
    Button button2 = (Button) findViewById(R.id.VideoButton);

    button1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

 //             Intent in1 = new Intent( MainActivity.this , theOptionsPage.class);
//                startActivity(in1);

        }
    });



}

}

<?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">

<TextView
    android:id="@+id/textView"
    android:layout_width="wrap_content"
    android:layout_height="44dp"
    android:layout_marginBottom="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:text="Would You Like Muisc or Videos"
    android:textAlignment="center"
    android:textAllCaps="false"
    android:textSize="20sp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.172" />

<Button
    android:id="@+id/MusicButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="8dp"
    android:layout_marginStart="80dp"
    android:layout_marginTop="116dp"
    android:text="Music"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/textView"
    app:layout_constraintVertical_bias="0.0" />

<Button
    android:id="@+id/VideoButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginEnd="72dp"
    android:text="Videos"
    app:layout_constraintBaseline_toBaselineOf="@+id/MusicButton"
    app:layout_constraintEnd_toEndOf="parent" />

</android.support.constraint.ConstraintLayout>

1 个答案:

答案 0 :(得分:0)

您好,如果您在button0点击事件中看到您的代码:

#!/bin/bash

openssl s_client -starttls smtp -crlf  -connect smtp.gmail.com:587
auth plain
(((((here is my login:pass))))
mail from: <test@gmail.com>
rcpt to: <test2@gmail.com>
data

my mail 
.

quit

在启动theOptionsPage activty之后,请立即调用openHappy();这就是它启动&#34; theOptionPage&#34;然后立即启动&#34; YoutubeHappy&#34;活性。

因此,在点击监听器中删除openHappy()调用,然后从&#34; theOptionPage&#34;

开始活动