dimanche 12 février 2017

Android Studlo passing data using a Bundle

Vote count: 0

I am trying to pass data to different activities using a Bundle. When I go to add data to the bundle I get an error with key value that says cannot resolve symbol Alcohol_question2. Could someone help me?

Here is my code from the StartScreen Activity that makes the Bundle.

package http://ift.tt/2l9yiTO;

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

// The first screen the user will see
public class StartScreen_MainActivity extends AppCompatActivity {

public static Bundle MyAppsBundle = new Bundle();


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_start_screen__main);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);



    final Button btn = (Button) findViewById(R.id.button);
    btn.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            launchActivity();
        }

        });
    }

// Switches to the Consent_MainActivity screen
private void launchActivity() {
    Intent intent = new Intent(this, Consent_MainActivity.class);
    startActivity(intent);
}

}

Here is my code from the Alcohol and Drug Activity

package http://ift.tt/2l9yiTO;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Spinner;

public class Alcohol_and_Drug_MainActivity extends AppCompatActivity {

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

    final Button btn = (Button) findViewById(R.id.Next_Screen7);
    btn.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            collectValues();
            launchNextScreenActivity();
        }
    });
}

private void collectValues() {
    Spinner q2 = (Spinner) findViewById(R.id.spinner30);
    String question2 = q2.getSelectedItem().toString();
     StartScreen_MainActivity.MyAppsBundle.putString(Alcohol_question2,question2);
}

// Switches to the travel_MainActivity screen
private void launchNextScreenActivity() {

    final Spinner spi = (Spinner) findViewById(R.id.spinner6);
    String experimentDrugs = spi.getSelectedItem().toString();

    Intent intent = new Intent(this, travel_MainActivity.class);
    startActivity(intent);

}

}

asked 33 secs ago

Let's block ads! (Why?)



Android Studlo passing data using a Bundle

Aucun commentaire:

Enregistrer un commentaire