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();
}



}

效果:




本文出自 “追随心的彼岸” 博客,谢绝转载!

更多相关文章

  1. Android软键盘弹出时不把布局顶上去的解决方法
  2. 输入法弹出后,不影响activity原有布局(android:windowSoftInputMo
  3. Android8.0 页面崩溃问题
  4. Android点击左右按钮实现左右滑动页面切换
  5. Android中的表格布局TableLayout
  6. Android 学习笔记6 —— Activity 布局学习1
  7. Android布局背景颜色设置

随机推荐

  1. Android-Toast的使用方法详解
  2. Android常见系统广播
  3. Android(安卓)系统中WiFi的部署
  4. android froyo framework内RIL.java类分
  5. 关于Android(安卓)7.0下Launcher3下defau
  6. android功耗(9)----MTK功耗问题需要哪种log
  7. Android中自定义适配器的使用
  8. Android(安卓)中View只能接收到ACTION_DO
  9. android mediaplayer概况
  10. 彻底理解Android沉浸状态栏适配