android之无返回结果跳转intent

android之无返回结果跳转intent:

(注意跳转的时候要传像user的对象必须实现Serializable接口)

登陆页面布局: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="输入编号:"/>
            <EditText 
              android:id="@+id/etUser"
                android:hint="请输入1-10个字符"/>
        </TableRow>
        <TableRow >
            <TextView  
                
                android:text="密码:"/>
            <EditText 
               android:id="@+id/etPassw"
                android:hint="请输入1-10个字符"
                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="登陆"
                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="退出"/>
            <Button 
                  android:visibility="invisible"
              />
        </TableRow>
    </TableLayout>


</LinearLayout>

登陆页面java程序:

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("编号不能为空");
return;
}
String passw = etPassw.getText().toString();
if(TextUtils.isEmpty(passw)){
etPassw.setError("密码不能为空");
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);
}



}

跳转页面布局: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>

跳转java代码:

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", "注册信息:"+user);
Toast.makeText(this,"注册信息:"+user, 2000).show();
}



}

效果:




  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值