Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Main activity
- package com.example.matheus.personagens;
- import android.content.Intent;
- import android.support.v7.app.ActionBarActivity;
- import android.os.Bundle;
- import android.view.Menu;
- import android.view.MenuItem;
- import android.view.View;
- import android.widget.TextView;
- public class MainActivity extends ActionBarActivity {
- Personagem[] personagens = new Personagem[10];
- int i=0;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.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();
- if (id == R.id.action_settings) {
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
- public void onCriarPersonagemButtonClick(View view) {
- //personagens[i] = new Personagem();
- Intent getNameScreenIntent = new Intent(this, GettingName.class);
- final int result = 1;
- startActivityForResult(getNameScreenIntent, result);
- //i++;
- }
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- super.onActivityResult(requestCode, resultCode, data);
- //GETTING PERSONAGEM
- personagens[i] = (Personagem) data.getSerializableExtra("sentPerso");
- TextView infoPerso = (TextView) findViewById(R.id.info_perso_text_view);
- infoPerso.append("Nome: " + personagens[i].getName() + ", idade: " + personagens[i].getAge() + ", altura: " + personagens[i].getAltura() + "\n");
- i++;
- }
- }
- //GettingName -----------------------------------------------------------------------------------
- package com.example.matheus.personagens;
- import android.app.Activity;
- import android.content.Intent;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.EditText;
- /**
- * Created by matheus on 28/07/14.
- */
- public class GettingName extends Activity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.layout_nome);
- }
- public void onNomeProximoClick(View view) {
- EditText nome = (EditText) findViewById(R.id.nome_edit_text);
- final int result = 1;
- String nameOfPerso = String.valueOf(nome.getText());
- Intent sendName = new Intent(this, GettingAge.class);
- sendName.putExtra("sentName", nameOfPerso);
- startActivityForResult(sendName, result);
- }
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- super.onActivityResult(requestCode, resultCode, data);
- Personagem persoStatico = (Personagem) data.getSerializableExtra("sentPerso");
- Intent goingBack = new Intent();
- goingBack.putExtra("sentPerso", persoStatico);
- //goingBack.putExtra("senha", "ola");
- setResult(RESULT_OK, goingBack);
- finish();
- }
- }
- //GettingAge -------------------------------------------------
- package com.example.matheus.personagens;
- import android.app.Activity;
- import android.content.Intent;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.EditText;
- import android.widget.TextView;
- /**
- * Created by matheus on 29/07/14.
- */
- public class GettingAge extends Activity{
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.idade);
- }
- public void onIdadeProximoClick(View view) {
- Intent gettingName = getIntent();
- String nameOfPerso = gettingName.getStringExtra("sentName");
- EditText age = (EditText) findViewById(R.id.idade_edit_text);
- final int result = 1;
- int ageOfPerso = Integer.parseInt(age.getText().toString());
- Intent sendNameAndAge = new Intent(this, GettingAltura.class);
- sendNameAndAge.putExtra("sentName", nameOfPerso);
- sendNameAndAge.putExtra("sentAge", ageOfPerso);
- startActivityForResult(sendNameAndAge, result);
- }
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- super.onActivityResult(requestCode, resultCode, data);
- Personagem persoStatico = (Personagem) data.getSerializableExtra("sentPerso");
- Intent goingBack = new Intent();
- goingBack.putExtra("sentPerso", persoStatico);
- //goingBack.putExtra("senha", "ola");
- setResult(RESULT_OK, goingBack);
- finish();
- }
- }
- //GettingAltura --------------------------------------------------------------------------------------
- package com.example.matheus.personagens;
- import android.app.Activity;
- import android.content.Intent;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.EditText;
- import android.widget.TextView;
- import org.w3c.dom.Text;
- /**
- * Created by matheus on 29/07/14.
- */
- public class GettingAltura extends Activity{
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.layout_altura);
- }
- public void onFinalizarButtonClick(View view) {
- //GETTING THE NAME AND AGE --------
- Intent getNameAndAge = getIntent();
- String nameOfPerso = getNameAndAge.getStringExtra("sentName");
- int ageOfPerso = getNameAndAge.getIntExtra("sentAge", 1);
- //GETTING THE ALTURA
- EditText altura = (EditText) findViewById(R.id.altura_edit_text);
- double alturaOfPerso = Double.parseDouble(altura.getText().toString());
- //CREATING THE PERSONAGEM OBJECT
- Personagem persoStatico = new Personagem(nameOfPerso, ageOfPerso, alturaOfPerso);
- //CREATING THE INTENT TO GET BACK
- Intent goingBack = new Intent();
- goingBack.putExtra("sentPerso", persoStatico);
- //goingBack.putExtra("senha", "ola");
- setResult(RESULT_OK, goingBack);
- finish();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement