Hey all,

I'm building my first Android app, and it's pretty confusing.  I'm
picking it up pretty well (or at least the minimal stuff I need to
know at this point), but I'm having one fairly significant issue.  I
haven't been able to figure out how to start a new activity.

I know to create an intent: Intent launchSuccess = new Intent()
and I know to call startActivity(Intent intentname)

However, I'm not sure what to send into Intent() or what I have to do
in AndroidManifest.xml to get it to work.

Here's what I have:

--------------------------------------------------------------------------------------------
AndrAIM.java
--------------------------------------------------------------------------------------------
public class AndrAIM extends Activity {
    /** Called when the activity is first created. */

        Intent launchSuccess = new Intent(AndrAIM.this, Success.class);

    // Create an anonymous class to act as a button click listener.
   private OnClickListener sign_in_listener = new OnClickListener()
    {
        public void onClick(View v)
        {
                getInfo();
        }
    };

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

        Button sign_in = (Button)findViewById(R.id.sign_in);
        sign_in.setOnClickListener(sign_in_listener);

    }

    public void getInfo(){
        final EditText passwordField = (EditText)
findViewById(R.id.password);
        String password = passwordField.getText().toString();

        final EditText unameField = (EditText)
findViewById(R.id.username);
        String username = unameField.getText().toString();

        if (validateLogin(username, password))
                startActivity(launchSuccess);

        else {

               TextView tv = new TextView(this);
               tv.setText("login failed!" + "\n" + "username: " +
username + "\n" + " password: " + password);
               setContentView(tv);
        }


    }

    public boolean validateLogin(String uname, String pword){
        if(uname.equals("username1"))
                if(pword.equals("password1"))
                        return true;
        return false;
    }
}

--------------------------------------------------------------------------------------------
main.xml
--------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
android:id="@+id/widget135"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android";
>
<TableLayout
android:id="@+id/widget164"
android:layout_width="317px"
android:layout_height="135px"
xmlns:android="http://schemas.android.com/apk/res/android";
android:orientation="vertical"
android:stretchColumns="1"
android:layout_x="0px"
android:layout_y="2px"
>
<TableRow
android:id="@+id/widget165"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android";
android:orientation="horizontal"
>
<TextView
android:id="@+id/widget168"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="AndrAIM"
>
</TextView>
</TableRow>
<TableRow
android:id="@+id/widget166"
android:layout_width="182px"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android";
android:orientation="horizontal"
>
<TextView
android:id="@+id/widget169"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Screen Name:"
>
</TextView>
<EditText
android:id="@+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
>
</EditText>
</TableRow>
<TableRow
android:id="@+id/widget167"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android";
android:orientation="horizontal"
>
<TextView
android:id="@+id/widget170"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password:"
>
</TextView>
<EditText
android:id="@+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
>
</EditText>
</TableRow>
</TableLayout>
<Button
android:id="@+id/sign_in"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sign in"
android:layout_x="240px"
android:layout_y="142px"
>
</Button>
</AbsoluteLayout>

The following is Success's entry in AndroidManifest.xml
 <activity android:label="@string/app_name" android:name="Success">
<intent-filter>
<action android:name="com.straightforwardcode.action.Success.MAIN">
</action></intent-filter></activity>


Any help would be greatly appreciated.

Thanks!

I have Success.java (which is the activity that I want to load) and
Success.xml, which defines its layout.

Essentially, I need to know what to do to get Success.java to load
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to