my problem is that when i try to set the text of service1 and service1Health in my code below, The text is not being set. Any ideas as to why this is happening? service1Name and service1HealthValue both have valid string values.
public void onClick(View v)
{
switch(v.getId())
{
case R.id.loginButton:
String[] values = new String[2];
String usernameText = ((TextView) activity.findViewById(R.id.usernameTextBox)).getText().toString();
String passwordText = ((TextView) activity.findViewById(R.id.txtPasswordField)).getText().toString();
if (usernameText.length()==0 || passwordText.length()==0)
Toast.makeText(activity, "Please fill in both username and password fields", Toast.LENGTH_SHORT).show();
else
{
Toast.makeText(activity, "Connecting to server", Toast.LENGTH_LONG).show();
String loginResult = Server.login(usernameText,passwordText);
values = loginResult.split(",");
Intent i = new Intent(activity,Home.class);
activity.startActivity(i);
activity.setContentView(R.layout.home);
String service1Name = Server.getServices("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
String service1HealthValue = Server.getHealth("myservice","xxxxxxxxxxxxxxxxxxxxxxxxxxx");
TextView service1= ((TextView) activity.findViewById(R.id.serviceName1));
TextView service1Health= ((TextView) activity.findViewById(R.id.service1Health));
service1.setText(service1Name);
service1Health.setText(service1HealthValue);
}
break;
}
}
When you call
activity.startActivity(i);, it launches a new activity, so any code after this, includingactivity.setContentView(R.layout.home);will not be reached, so none of theseTextViewswill get set. If you want to set these values in the new activity, you should add them to theIntent, then reopen them in theonCreatemethod of the newActivity. So for example, in your current Activity:And in the onCreate method of
Home.java, add the following: