登陆界面,头像选择,activity之间的值传递!

布局代码如下:

activity_main :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/center"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >
    <LinearLayout android:id="@+id/lin2"
         android:layout_height="match_parent"
         android:layout_width="wrap_content"
         android:layout_weight="1"
         android:orientation="vertical">
         <ImageView 
             android:layout_marginTop="90dp"
             android:layout_marginLeft="20dp"
             android:id="@+id/img"
             android:layout_width="100dp"
             android:layout_height="100dp"
             android:background="@drawable/ic_launcher"/>
         <Button android:id="@+id/btn"
             android:layout_height="wrap_content"
             android:layout_width="wrap_content"
             android:text="选择头像"
             android:layout_marginLeft="20dp"/>
         
        
    </LinearLayout>

    <LinearLayout android:id="@+id/lin1"
         android:layout_height="match_parent"
         android:layout_width="wrap_content"
         android:layout_weight="2"
         android:orientation="vertical">

        <TextView
            android:id="@+id/tv1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="用户名:" />

        <EditText
            android:id="@+id/ed1"
            android:layout_width="match_parent"
            android:layout_height="30dp" />

        <TextView
            android:id="@+id/tv2"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="密码:" />

        <EditText
            android:id="@+id/ed2"
            android:layout_width="match_parent"
            android:layout_height="30dp"
            android:inputType="textPassword" />

        <TextView
            android:id="@+id/tv3"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="再次输入密码:" />

        <EditText
            android:id="@+id/ed3"
            android:layout_width="match_parent"
            android:layout_height="30dp"
            android:inputType="textPassword" />

        <TextView
            android:id="@+id/tv4"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="邮箱:" />

        <EditText
            android:id="@+id/ed4"
            android:layout_width="match_parent"
            android:layout_height="30dp" />

        <Button
            android:id="@+id/bt1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="提交" />
    </LinearLayout>
    

</LinearLayout>

activity_two_main:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/center"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/tv5"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="用户名" />

    <TextView
        android:id="@+id/tv6"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="密码" />

    <TextView
        android:id="@+id/tv7"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="邮箱" />

    <Button
        android:id="@+id/bt2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="返回上一步" />

</LinearLayout>

activity_three_main:


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <GridView
        android:id="@+id/grd"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="10px"
        android:horizontalSpacing="3px"
        android:numColumns="4"
        android:verticalSpacing="3px" >
    </GridView>

</LinearLayout>


功能代码如下:

MainActivity 文件代码:

package com.example.touxiang;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;

public class MainActivity extends Activity {
	private EditText ed1, ed2, ed3, ed4;
	private Button bt1,btn;
	private final int CODE = 0x717;

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		ed1 = (EditText) findViewById(R.id.ed1);
		ed2 = (EditText) findViewById(R.id.ed2);
		ed3 = (EditText) findViewById(R.id.ed3);
		ed4 = (EditText) findViewById(R.id.ed4);
		bt1 = (Button) findViewById(R.id.bt1);
		btn=(Button) findViewById(R.id.btn);
		bt1.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				Intent it = new Intent();
				it.setClass(MainActivity.this, TwoMainActivity.class);// 意图!跳转!
				Bundle bl = new Bundle();
				bl.putString("z", ed1.getText().toString());
				bl.putString("x", ed2.getText().toString());
				bl.putString("y", ed4.getText().toString());
				it.putExtras(bl);
				startActivityForResult(it, CODE);
			}
		});
		
		btn.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				Intent intent=new Intent(MainActivity.this,ThreeMainActivity.class);
				startActivityForResult(intent, 0x11);
			}
		});
		

	}
	protected void onActivityResult(int requestCode,int resultCode,Intent data){
		super.onActivityResult(requestCode, resultCode, data);
		if (requestCode==CODE && resultCode==CODE) {
			((EditText)findViewById(R.id.ed2)).setText("");
			((EditText)findViewById(R.id.ed3)).setText("");
		}
		if (requestCode==0x11 && resultCode==0x11) {
			Bundle bundle=data.getExtras();
			int imageId=bundle.getInt("imageId");
			ImageView iv=(ImageView) findViewById(R.id.img);
			iv.setImageResource(imageId);
			
		}
	}

}

TwoMainActivity 文件代码:


package com.example.touxiang;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class TwoMainActivity extends Activity {

	protected static final Intent[] MainActivity = null;
	private Button bt2;
	private TextView tv5, tv6, tv7;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_two_main);
		bt2 = (Button) findViewById(R.id.bt2);
		tv5 = (TextView) findViewById(R.id.tv5);
		tv6 = (TextView) findViewById(R.id.tv6);
		tv7 = (TextView) findViewById(R.id.tv7);
		Intent it = this.getIntent();
		Bundle bl1 = it.getExtras();
		String s1 = bl1.getString("z");
		String s2 = bl1.getString("x");
		String s3 = bl1.getString("y");
		tv5.setText(s1);
		tv6.setText(s2);
		tv7.setText(s3);
		bt2.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				setResult(0x717);
				finish();
			}
		});
	}
}



ThreeMainActivity文件代码:


package com.example.touxiang;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;

public class ThreeMainActivity extends Activity {
	public int[] imageId = new int[] { R.drawable.wardskin_15,
			R.drawable.wardskin_16, R.drawable.wardskin_17,
			R.drawable.wardskin_18, R.drawable.wardskin_19,
			R.drawable.wardskin_20, R.drawable.wardskin_21,
			R.drawable.wardskin_22, R.drawable.wardskin_27 };

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_three_main);
		GridView grd = (GridView) findViewById(R.id.grd);
		BaseAdapter adapter = new BaseAdapter() {

			@Override
			public View getView(int position, View convertView, ViewGroup parent) {
				// TODO Auto-generated method stub
				ImageView imageView;
				if (convertView == null) {
					imageView = new ImageView(ThreeMainActivity.this);
					imageView.setAdjustViewBounds(true);
					imageView.setMaxWidth(158);
					imageView.setMaxHeight(150);
					imageView.setPadding(5, 5, 5, 5);

				} else {
					imageView = (ImageView) convertView;
				}
				imageView.setImageResource(imageId[position]);
				return imageView;
			}

			@Override
			public long getItemId(int position) {
				// TODO Auto-generated method stub
				return position;
			}

			@Override
			public Object getItem(int position) {
				// TODO Auto-generated method stub
				return position;
			}

			@Override
			public int getCount() {
				// TODO Auto-generated method stub
				return imageId.length;
			}
		};
		grd.setAdapter(adapter);
		grd.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				// TODO Auto-generated method stub
				Intent intent = getIntent();
				Bundle bundle = new Bundle();
				bundle.putInt("imageId", imageId[position]);
				intent.putExtras(bundle);
				setResult(0x11, intent);
				finish();
			}

		});
	}

}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值