title: setText on button from another activity android
body: <p>I have a problem, I want to click on the list, calling a new activity and rename the button to another name.</p>
  <p>I tried several things, nothing worked, can someone please help me?</p>
  <p>My class <code>EditarTimes</code>:</p>
  <pre>private AdapterView.OnItemClickListener selecionarTime = new AdapterView.OnItemClickListener() {
  
      public void onItemClick(AdapterView arg0, View arg1, int pos, long id) {
          t = times.get(pos);
  
          <strike>CadastroTimes cad = new CadastroTimes();</strike>
          <strike>CadastroTimes.salvar.setText("Alterar");</strike>
          Intent intent = new Intent(EditarTimes.this, CadastroTimes.class);
          startActivity(intent);
  
  
      }
  
  };</pre>
  <pre class="lang-java prettyprint-override"><code>public class CadastroTimes extends AppCompatActivity {
  
      private Time t;
      private timeDatabase db;
      private EditText edID;
      private EditText edNome;
      public Button salvar;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_cadastro_times);
  
          edID = (EditText) findViewById(R.id.edID);
          edNome = (EditText) findViewById(R.id.edNome);
          db = new timeDatabase(getApplicationContext());
          salvar = (Button) findViewById(R.id.btnCadastrar);
          salvar.setText(&quot;Cadastrar&quot;);
          String newString;
          if (savedInstanceState == null) {
              Bundle extras = getIntent().getExtras();
              if(extras == null) {
                  newString= null;
              } else {
                  newString= extras.getString(&quot;Alterar&quot;);
              }
          } else {
              newString= (String) savedInstanceState.getSerializable(&quot;Alterar&quot;);
          }
  
          //button in CadastroTimes activity to have that String as text
          System.out.println(newString + &quot; AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA&quot;);
          salvar.setText(newString);
      }
  
      public void salvarTime(View v) {
          t = new Time();
          t.setNome(edNome.getText().toString());
  
          if (salvar.getText().equals(&quot;Alterar&quot;)) {
              db.atualizar(t);
              exibirMensagem(&quot;Time atualizado com sucesso!&quot;);
          } else {
              db.salvar(t);
              exibirMensagem(&quot;Time cadastrado com sucesso!&quot;);
          }
  
          Intent intent = new Intent(this, EditarTimes.class);
          startActivity(intent);
  
      }
  
  
      private void limparDados() {
          edID.setText(&quot;&quot;);
          edNome.setText(&quot;&quot;);
          edNome.requestFocus();
      }
  
      private void exibirMensagem(String msg) {
          Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show();
      }
  
  }
  </code></pre>
  <pre class="lang-java prettyprint-override"><code>public class EditarTimes extends AppCompatActivity {
  
      private Time t;
      private List&lt;Time&gt; times;
      private timeDatabase db;
      private ListView lvTimes;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_editar_times);
  
          lvTimes = (ListView) findViewById(R.id.lvTimes);
          lvTimes.setOnItemClickListener(selecionarTime);
          lvTimes.setOnItemLongClickListener(excluirTime);
          times = new ArrayList&lt;Time&gt;();
          db = new timeDatabase(getApplicationContext());
          atualizarLista();
      }
  
      private void excluirTime(final int idTime) {
  
  
          AlertDialog.Builder builder = new AlertDialog.Builder(this);
          builder.setTitle(&quot;Excluir time?&quot;)
                  .setIcon(android.R.drawable.ic_dialog_alert)
                  .setMessage(&quot;Deseja excluir esse time?&quot;)
                  .setCancelable(false)
                  .setPositiveButton(getString(R.string.sim),
                          new DialogInterface.OnClickListener() {
                              public void onClick(DialogInterface dialog, int id) {
                                  if (db.deletar(idTime)) {
                                      atualizarLista();
                                      exibirMensagem(getString(R.string.msgExclusao));
                                  } else {
                                      exibirMensagem(getString(R.string.msgFalhaExclusao));
                                  }
  
                              }
                          })
                  .setNegativeButton(getString(R.string.nao),
                          new DialogInterface.OnClickListener() {
                              public void onClick(DialogInterface dialog, int id) {
                                  dialog.cancel();
                              }
                          });
          builder.create();
          builder.show();
  
          atualizarLista();
  
      }
  
      private void atualizarLista() {
  
          times = db.listAll();
          if (times != null) {
              if (times.size() &gt; 0) {
                  TimeListAdapter tla = new TimeListAdapter(
                          getApplicationContext(), times);
                  lvTimes.setAdapter(tla);
              }
  
          }
  
      }
  
      private AdapterView.OnItemClickListener selecionarTime = new AdapterView.OnItemClickListener() {
  
          public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1, int pos, long id) {
              t = times.get(pos);
  
              Intent intent = new Intent(EditarTimes.this, CadastroTimes.class);
              String strName = &quot;Alterar&quot;;
              intent.putExtra(&quot;Alterar&quot;, strName);
              startActivity(intent);
          }
  
      };
  
      private AdapterView.OnItemLongClickListener excluirTime = new AdapterView.OnItemLongClickListener() {
  
          public boolean onItemLongClick(AdapterView&lt;?&gt; arg0, View arg1,
                                         int pos, long arg3) {
              excluirTime(times.get(pos).getId());
              return true;
          }
  
      };
  
      private void exibirMensagem(String msg) {
          Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show();
      }
  
      public void telaCadastrar(View view) {
          Intent intent = new Intent(this, CadastroTimes.class);
          startActivity(intent);
      }
  
      public void botaoSair(View view) {
          Intent intent = new Intent(this, TelaInicial.class);
          startActivity(intent);
      }
  }
  </code></pre>