I followed this tutorial (It’s old, but I couldn’t find any others; http://learnandroid.blogspot.com/2008/01/opening-new-screen-in-android.html)
So, I have it so that when I click on some text, it should open a different layout.
This is the XML code for the text I click on to open it:
<TextView android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_height="wrap_content"
android:text="Not a member? Sign up now!"
android:layout_width="wrap_content"
android:id="@+id/signupText"
android:layout_gravity="center"></TextView>
</LinearLayout>
And this is the Java coding for the Layout with the clickable text on it (The first “screen”):
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
public class NetworkActivity extends Activity {
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);
setContentView(R.layout.main);
TextView click = (TextView) findViewById(R.id.signupText);
click.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
Intent i = new Intent(NetworkActivity.this, Signup.class);
startActivity(i);
}
});
}
}
The Java code for the second layout:
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
public class Signup extends Activity
{
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);
setContentView(R.layout.signup);
TextView b = (TextView) findViewById(R.id.signupText);
b.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
setResult(RESULT_OK);
finish();
}
});
}
}
There’s nothing special in the XML code for the second layout. (Should there be?)
When I click on the text in the Emulator, I get the error message that it’s closed unexpectedly. How do I fix this?
Oh, and I saw other questions kind of like mine, but they weren’t any help. I’m new to all this, so please don’t get angry if I’ve done something “wrong”. Thanks for the help in advance. =]
Most likely you didn’t register your second activity in your android manifest. You need to create a
<activity>tag for each one in your app. There should be an error in the logcat, basically saying “Could not find activity (Have you declared it in your manifest?)”.All you have to do to fix this, is add the tag inside your
<application>tag:See the
<activity>tag documentation for further information.