android之無返回結果跳轉intent

來源:互聯網
上載者:User

標籤:android   介面   layout   

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



}

效果:

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

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


本文出自 “追隨心的彼岸” 部落格,謝絕轉載!

android之無返回結果跳轉intent

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.