So i am very new at this android and Java in generel. However, i do know c++, php among others, but this s*** is just not working for me, so i hope you can help me.
I guess it is a pretty simple and easy answer, however i cannot seem to get it to work. I have tried using spinners in the way the official "android" help says, but then i do not seem to be able to save the data and transfer it to another class.
So my code is this:
package com.example.handballstats;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
public class NewGameScreen extends Activity {
ArrayAdapter<String> HomePlayer1Adapter;
ArrayAdapter<String> AwayPlayer1Adapter;
int [] valueHomePlayer1Array = {0,25};
int [] valueAwayPlayer1Array = {0,25};
Spinner HomePlayer1Spinner;
Spinner AwayPlayer1Spinner;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_new_game_screen);
HomePlayer1Spinner = (Spinner) findViewById(R.id.spinner1);
AwayPlayer1Spinner= (Spinner) findViewById(R.id.spinner2);
loadHomePlayer1Range();
loadAwayPlayer1Range();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.new_game_screen, menu);
return true;
}
public void loadHomePlayer1Range() {
HomePlayer1Spinner.setAdapter(HomePlayer1Adapter);
HomePlayer1Spinner.setSelection(HomePlayer1Adapter.getPosition("400"));
}
public void loadAwayPlayer1Range() {
AwayPlayer1Spinner.setAdapter(AwayPlayer1Adapter);
AwayPlayer1Spinner.setSelection(AwayPlayer1Adapter.getPosition("77"));
}
public void game_start (View view){
Intent game_start_intent = new Intent(NewGameScreen.this, GameStartScreen.class);
game_start_intent.putExtra("Data1", valueHomePlayer1Array);
game_start_intent.putExtra("Data2", valueAwayPlayer1Array);
NewGameScreen.this.startActivity(game_start_intent);
}
}
I want the two spinners to have values from 0-25. Then i want to be able to save these values and import them in a new class using something like:
Private String data1;
Private String data2;
Private int data3;
Bundle extras = getIntent().getExtras();
if (extras != null) {
data1 = extras.getString("Data1");
data2 = extras.getString("Data2");
data3 = extras.getInt("Data3");
}
Intent myIntent = new Intent(Activity2.this, Activity3.class);
myIntent.putExtra("Data1", data1);
myIntent.putExtra("Data2", data2);
myIntent.putExtra("Data3", data3);
Activity2.this.startActivity(myIntent);
Can someone help me, with what i am doing wrong in the first activity?