Android no return results jump intent

Source: Internet
Author: User

Android no return results jump intent:

(Note that the object to be passed as the user must implement the serializable interface when jumping)

Landing Page layout:layout/activity_login.xml:

<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Xmlns:tools= "Http://schemas.android.com/tools"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
android:orientation= "Vertical" >


<tablelayout
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:stretchcolumns= "1" >
<tablerow
>
<textview
android:text= "Enter Number:"/>
<edittext
Android:id= "@+id/etuser"
Android:hint= "Please enter 1-10 characters"/>
</TableRow>
<tablerow >
<textview

android:text= "Password:"/>
<edittext
Android:id= "@+id/etpassw"
Android:hint= "Please enter 1-10 characters"
Android:password= "true"/>

</TableRow>
</TableLayout>
<tablelayout
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
>
<tablerow >
<button
android:visibility= "Invisible"
/>
<button
Android:id= "@+id/register"
android:text= "Login"
android:drawableleft= "@drawable/login32x32"
android:background= "@drawable/btn_bg"/>
<button
android:visibility= "Invisible"
/>
<button
Android:id= "@+id/exit"
android:drawableleft= "@drawable/exit32x32"
android:background= "@drawable/BTN_BG"
android:text= "Exit"/>
<button
android:visibility= "Invisible"
/>
</TableRow>
</TableLayout>


</LinearLayout>

Landing Page Java program:

Package com.example.day04_01;


Import android.support.v7.app.ActionBarActivity;
Import Android.test.UiThreadTest;
Import Android.text.TextUtils;
Import android.content.Intent;
Import Android.os.Bundle;
Import Android.os.SystemClock;
Import Android.view.Menu;
Import Android.view.MenuItem;
Import Android.view.View;
Import Android.view.View.OnClickListener;
Import Android.widget.EditText;


public class Loginactivity extends Actionbaractivity {
Private EditText ETUSER,ETPASSW;
@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_login);
Init ();
Setlistener ();
}
private void Setlistener () {
TODO auto-generated Method Stub
Findviewbyid (R.id.register). Setonclicklistener (New Onclicklistener () {

@Override
public void OnClick (view view) {
TODO auto-generated Method Stub
String code = Etuser.gettext (). toString ();
if (Textutils.isempty (code)) {
Etuser.seterror ("Number cannot be empty");
Return
}
String PASSW = Etpassw.gettext (). toString ();
if (Textutils.isempty (PASSW)) {
Etpassw.seterror ("Password cannot be empty");
Return
}
Intent Intent = new Intent (loginactivity.this,mainactivity.class);
Intent.putextra ("code", code);
Intent.putextra ("password", PASSW);
User user = new user (CODE,PASSW);
Intent.putextra ("user", user);
StartActivity (Intent);
}
});

Findviewbyid (R.id.exit). Setonclicklistener (New Onclicklistener () {

@Override
public void OnClick (view view) {
TODO auto-generated Method Stub
Finish ();
}
});
}
private void init () {
TODO auto-generated Method Stub
Etuser = (EditText) Findviewbyid (R.id.etuser);
etpassw= (EditText) Findviewbyid (R.ID.ETPASSW);
}



}

jump page Layout: Layout/activity_main.xml:

<relativelayout xmlns:android= " Http://schemas.android.com/apk/res/android "
    xmlns:tools=" Http://schemas.android.com/tools "
    android:layout_width= "match_parent"
    android:layout_height= "match_parent"
    android:paddingbottom= "@dimen/activity_vertical_margin"
    android:paddingleft= "@dimen/ Activity_horizontal_margin "
    android:paddingright=" @dimen/activity_horizontal_margin "
    android:paddingtop= "@dimen/activity_vertical_margin"
    tools:context= "com.example.day04_01. Mainactivity


    <textview
        android:layout_width= "Wrap_ Content "
        android:layout_height=" wrap_content "
        Android: text= "@string/hello_world"/>


</relativelayout>

Jump Java code:

Package com.example.day04_01;


Import android.support.v7.app.ActionBarActivity;
Import android.content.Intent;
Import Android.os.Bundle;
Import Android.util.Log;
Import Android.view.Menu;
Import Android.view.MenuItem;
Import Android.widget.Toast;


public class Mainactivity extends Actionbaractivity {


@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
Intent Intent = Getintent ();
String code = Intent.getstringextra ("code");
String PASSW = Intent.getstringextra ("password");
User user = (user) Intent.getserializableextra ("User");
LOG.I ("main", "Registration Information:" +user);
Toast.maketext (This, "Registration information:" +user,). Show ();
}



}

Effect:

650) this.width=650; "src=" http://img.blog.csdn.net/20141123190434288 "/>

650) this.width=650; "src=" http://img.blog.csdn.net/20141123190440793 "/>


This article from "Follow the heart of the other side" blog, declined reprint!

Android no return results jump intent

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.