Good day!

Porting my client-server chat for Android. I have two activations with the settings of either the client or the server, where at the touch of a button, the parameters must be set and the activit changes to another. But the problem is that the activation does not change. I commented out most of the code for all three activations, but it didn't help.

Here is a part of the code (only the client part, because they are similar in the initialization):

ClientSetting:

public class ClientSettings extends AppCompatActivity { private EditText edit_nickname; private EditText edit_serverIP; private String nickname; private String serverIP; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_client_settings); edit_nickname = (EditText) findViewById(R.id.edit_nickname); edit_serverIP = (EditText) findViewById(R.id.edit_serverIP); Button btn_connect = (Button) findViewById(R.id.btn_connect); View.OnClickListener listenerConnect = new View.OnClickListener() { @Override public void onClick(View view) { nickname = edit_nickname.getText().toString(); serverIP = edit_serverIP.getText().toString(); setContentView(R.layout.activity_functional); } }; btn_connect.setOnClickListener(listenerConnect); } } 

FunctionalActivity:

 public class FunctionalActivity extends AppCompatActivity { static private EditText edit_msg; static private Button btn_send; static private TextView msgBox; static private String msg; private Client client; private Server server; static private String nickname; static private String serverIP; static private String serverName; static private String maxConnections; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_functional); View.OnClickListener listenerSend = new View.OnClickListener() { @Override public void onClick(View view) { msg = edit_msg.getText().toString(); } }; } static String waitAndGetMsg() { while (true) { if (btn_send.callOnClick()) { if (!msg.isEmpty()) { return msg; } } } } public static void msgBoxSetText(String str) { msgBox.setText(str); } static void msgBoxAddText(String str) { msgBox.append(str); } } 

UPD: Experimenting, I learned that it turns out from ClientSettings and ServerSettings in general does not change the activation

    2 answers 2

    In the ClientSettings class, when processing OnClickListener delete setContentView(R.layout.activity_functional); and add a call to activity


    Example:

     View.OnClickListener listenerConnect = new View.OnClickListener() { @Override public void onClick(View view) { nickname = edit_nickname.getText().toString(); serverIP = edit_serverIP.getText().toString(); Intent intent = new Intent(this, FunctionalActivity.class); startActivity(intent); // вызов другой activity } }; 

    Study

      Instead

        setContentView(R.layout.activity_functional); 

      Need to write

        Intent intent = new Intent(this, FunctionalActivity.class); startActivity(intent);