Advertisement
Guest User

Personagens

a guest
Jul 29th, 2014
406
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.59 KB | None | 0 0
  1. //Main activity
  2.  
  3. package com.example.matheus.personagens;
  4.  
  5. import android.content.Intent;
  6. import android.support.v7.app.ActionBarActivity;
  7. import android.os.Bundle;
  8. import android.view.Menu;
  9. import android.view.MenuItem;
  10. import android.view.View;
  11. import android.widget.TextView;
  12.  
  13.  
  14. public class MainActivity extends ActionBarActivity {
  15.  
  16.     Personagem[] personagens = new Personagem[10];
  17.     int i=0;
  18.  
  19.     @Override
  20.     protected void onCreate(Bundle savedInstanceState) {
  21.         super.onCreate(savedInstanceState);
  22.         setContentView(R.layout.activity_main);
  23.  
  24.     }
  25.  
  26.  
  27.     @Override
  28.     public boolean onCreateOptionsMenu(Menu menu) {
  29.         // Inflate the menu; this adds items to the action bar if it is present.
  30.         getMenuInflater().inflate(R.menu.main, menu);
  31.         return true;
  32.     }
  33.  
  34.     @Override
  35.     public boolean onOptionsItemSelected(MenuItem item) {
  36.         // Handle action bar item clicks here. The action bar will
  37.         // automatically handle clicks on the Home/Up button, so long
  38.         // as you specify a parent activity in AndroidManifest.xml.
  39.         int id = item.getItemId();
  40.         if (id == R.id.action_settings) {
  41.             return true;
  42.         }
  43.         return super.onOptionsItemSelected(item);
  44.     }
  45.  
  46.     public void onCriarPersonagemButtonClick(View view) {
  47.  
  48.         //personagens[i] = new Personagem();
  49.  
  50.         Intent getNameScreenIntent = new Intent(this, GettingName.class);
  51.  
  52.         final int result = 1;
  53.  
  54.         startActivityForResult(getNameScreenIntent, result);
  55.  
  56.         //i++;
  57.  
  58.     }
  59.  
  60.     @Override
  61.     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  62.         super.onActivityResult(requestCode, resultCode, data);
  63.  
  64.         //GETTING PERSONAGEM
  65.         personagens[i] = (Personagem) data.getSerializableExtra("sentPerso");
  66.  
  67.         TextView infoPerso = (TextView) findViewById(R.id.info_perso_text_view);
  68.         infoPerso.append("Nome: " + personagens[i].getName() + ", idade: " + personagens[i].getAge() + ", altura: " + personagens[i].getAltura() + "\n");
  69.  
  70.         i++;
  71.     }
  72. }
  73.  
  74. //GettingName -----------------------------------------------------------------------------------
  75. package com.example.matheus.personagens;
  76.  
  77. import android.app.Activity;
  78. import android.content.Intent;
  79. import android.os.Bundle;
  80. import android.view.View;
  81. import android.widget.EditText;
  82.  
  83. /**
  84.  * Created by matheus on 28/07/14.
  85.  */
  86. public class GettingName extends Activity {
  87.  
  88.     @Override
  89.     protected void onCreate(Bundle savedInstanceState) {
  90.         super.onCreate(savedInstanceState);
  91.  
  92.         setContentView(R.layout.layout_nome);
  93.  
  94.     }
  95.  
  96.     public void onNomeProximoClick(View view) {
  97.         EditText nome = (EditText) findViewById(R.id.nome_edit_text);
  98.         final int result = 1;
  99.  
  100.         String nameOfPerso = String.valueOf(nome.getText());
  101.  
  102.         Intent sendName = new Intent(this, GettingAge.class);
  103.  
  104.         sendName.putExtra("sentName", nameOfPerso);
  105.  
  106.         startActivityForResult(sendName, result);
  107.  
  108.  
  109.     }
  110.  
  111.     @Override
  112.     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  113.         super.onActivityResult(requestCode, resultCode, data);
  114.  
  115.         Personagem persoStatico  = (Personagem) data.getSerializableExtra("sentPerso");
  116.  
  117.         Intent goingBack = new Intent();
  118.  
  119.         goingBack.putExtra("sentPerso", persoStatico);
  120.         //goingBack.putExtra("senha", "ola");
  121.  
  122.         setResult(RESULT_OK, goingBack);
  123.  
  124.  
  125.         finish();
  126.     }
  127. }
  128.  
  129. //GettingAge -------------------------------------------------
  130.  
  131. package com.example.matheus.personagens;
  132.  
  133. import android.app.Activity;
  134. import android.content.Intent;
  135. import android.os.Bundle;
  136. import android.view.View;
  137. import android.widget.EditText;
  138. import android.widget.TextView;
  139.  
  140. /**
  141.  * Created by matheus on 29/07/14.
  142.  */
  143.  
  144. public class GettingAge extends Activity{
  145.  
  146.     @Override
  147.     protected void onCreate(Bundle savedInstanceState) {
  148.         super.onCreate(savedInstanceState);
  149.  
  150.         setContentView(R.layout.idade);
  151.  
  152.     }
  153.  
  154.     public void onIdadeProximoClick(View view) {
  155.  
  156.         Intent gettingName = getIntent();
  157.  
  158.         String nameOfPerso = gettingName.getStringExtra("sentName");
  159.  
  160.         EditText age = (EditText) findViewById(R.id.idade_edit_text);
  161.         final int result = 1;
  162.  
  163.         int ageOfPerso = Integer.parseInt(age.getText().toString());
  164.  
  165.         Intent sendNameAndAge = new Intent(this, GettingAltura.class);
  166.  
  167.         sendNameAndAge.putExtra("sentName", nameOfPerso);
  168.         sendNameAndAge.putExtra("sentAge", ageOfPerso);
  169.  
  170.         startActivityForResult(sendNameAndAge, result);
  171.  
  172.     }
  173.  
  174.     @Override
  175.     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  176.         super.onActivityResult(requestCode, resultCode, data);
  177.  
  178.         Personagem persoStatico  = (Personagem) data.getSerializableExtra("sentPerso");
  179.  
  180.         Intent goingBack = new Intent();
  181.  
  182.         goingBack.putExtra("sentPerso", persoStatico);
  183.         //goingBack.putExtra("senha", "ola");
  184.  
  185.         setResult(RESULT_OK, goingBack);
  186.  
  187.  
  188.         finish();
  189.     }
  190. }
  191.  
  192. //GettingAltura --------------------------------------------------------------------------------------
  193. package com.example.matheus.personagens;
  194.  
  195. import android.app.Activity;
  196. import android.content.Intent;
  197. import android.os.Bundle;
  198. import android.view.View;
  199. import android.widget.EditText;
  200. import android.widget.TextView;
  201.  
  202. import org.w3c.dom.Text;
  203.  
  204. /**
  205.  * Created by matheus on 29/07/14.
  206.  */
  207. public class GettingAltura extends Activity{
  208.  
  209.     @Override
  210.     protected void onCreate(Bundle savedInstanceState) {
  211.         super.onCreate(savedInstanceState);
  212.  
  213.         setContentView(R.layout.layout_altura);
  214.     }
  215.  
  216.  
  217.     public void onFinalizarButtonClick(View view) {
  218.  
  219.         //GETTING THE NAME AND AGE --------
  220.         Intent getNameAndAge = getIntent();
  221.  
  222.         String nameOfPerso = getNameAndAge.getStringExtra("sentName");
  223.         int ageOfPerso = getNameAndAge.getIntExtra("sentAge", 1);
  224.  
  225.         //GETTING THE ALTURA
  226.         EditText altura = (EditText) findViewById(R.id.altura_edit_text);
  227.  
  228.         double alturaOfPerso = Double.parseDouble(altura.getText().toString());
  229.  
  230.         //CREATING THE PERSONAGEM OBJECT
  231.         Personagem persoStatico = new Personagem(nameOfPerso, ageOfPerso, alturaOfPerso);
  232.  
  233.         //CREATING THE INTENT TO GET BACK
  234.         Intent goingBack = new Intent();
  235.  
  236.         goingBack.putExtra("sentPerso", persoStatico);
  237.         //goingBack.putExtra("senha", "ola");
  238.  
  239.         setResult(RESULT_OK, goingBack);
  240.  
  241.         finish();
  242.     }
  243. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement