How to pick up values and play in another class? Android

Asked

Viewed 1,732 times

2

I have the following class:

 public class RetornaUsuarioActivity extends Activity  {    

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    AcessoRest ar = new AcessoRest();
    String chamadaWS;
    chamadaWS = "http://www.cordeiro-it.com.br/SOUPROGRESSO/Ctrl/recuperaUser.php";
    String resultado = ar.chamadaGet(chamadaWS);
    System.out.println(resultado);
    Log.i("JSON:",resultado);

    try {
        // Tratamento de erros
         JSONObject jsonResponse = new JSONObject(resultado);
         JSONArray usuarios = jsonResponse.getJSONArray("usuarios");

         for(int i=0; i < usuarios.length(); i++) {
             JSONObject jsonobject = usuarios.getJSONObject(i);
             String nome = jsonobject.getString("nome");
             String cpf = jsonobject.getString("cpf");

             /*TextView tv = (TextView) findViewById(R.id.txtMessage);
             tv.setText(nome);*/
          }  

    } catch (Exception e) {
        // ERRO
        e.printStackTrace();
        System.out.println("Erro ao retornar dados do usuário");
    }

}

}

Like I pick up and play the values of NAME AND NUMBER who are in that for in another class of Activity?

Type I want to take these values to see if the user exists or not, then save to a TXT file.

  • you can pass values between Activitys using Parcelable and Serializable, take a look at this question [http://answall.com/a/70456/10315] where @sicachester answered in the morning can help you

1 answer

2

To send data:

EditText editText1 = (EditText) findViewById(R.id.name);
EditText editText2 = (EditText) findViewById(R.id.ma);
String message = "Oi! " + editText1.getText().toString();
int i = Integer.parseInt(editText2.getText().toString());

Bundle param = new Bundle();
param.putString("greeting",message);
param.putInteger("NumberInteger",i);

Intent intent = new Intent(this, DisplayMessageActivity.class);
intent.putExtras(param);
startActivity(intent);

To receive, then, in the Displaymessageactivity.java class do so:

Intent it = getIntent();
Bundle param = it.getExtras();
String capturedMessage= param.getString("greeting");
Integer captured_I = param.getInteger("NumberInteger");

Browser other questions tagged

You are not signed in. Login or sign up in order to post.