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

来源:互联网 发布:java后台框架源码 编辑:程序博客网 时间:2024/04/29 06:13

布局代码如下:

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() {@Overridepublic void onClick(View arg0) {// TODO Auto-generated method stubIntent 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() {@Overridepublic void onClick(View arg0) {// TODO Auto-generated method stubIntent 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() {@Overridepublic void onClick(View arg0) {// TODO Auto-generated method stubsetResult(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 };@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_three_main);GridView grd = (GridView) findViewById(R.id.grd);BaseAdapter adapter = new BaseAdapter() {@Overridepublic View getView(int position, View convertView, ViewGroup parent) {// TODO Auto-generated method stubImageView 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;}@Overridepublic long getItemId(int position) {// TODO Auto-generated method stubreturn position;}@Overridepublic Object getItem(int position) {// TODO Auto-generated method stubreturn position;}@Overridepublic int getCount() {// TODO Auto-generated method stubreturn imageId.length;}};grd.setAdapter(adapter);grd.setOnItemClickListener(new OnItemClickListener() {@Overridepublic void onItemClick(AdapterView<?> parent, View view,int position, long id) {// TODO Auto-generated method stubIntent intent = getIntent();Bundle bundle = new Bundle();bundle.putInt("imageId", imageId[position]);intent.putExtras(bundle);setResult(0x11, intent);finish();}});}}



1 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 电视电源板坏了怎么办 手机电路板坏了怎么办 iqos主板坏了怎么办 电脑开关没反应怎么办 电子邮件密码忘了怎么办 微信被限制进群怎么办 电子邮箱密码忘了怎么办 qq邮件收不到怎么办 电子邮件密码忘记了怎么办 孩子一烧就39度怎么办 qq邮箱找不到了怎么办 忘记网易邮箱账号怎么办 企业微信用不了怎么办 qq邮箱密码被盗怎么办 企业邮箱密码忘了怎么办 icloud登入不了怎么办 qq邮件加载失败怎么办 收货数量少了怎么办 邮箱附件过期了怎么办 邮箱附件已过期怎么办 163邮箱附件过大怎么办 126邮箱内容过期怎么办 授权码忘记了怎么办 163邮箱忘记账号怎么办 126邮箱忘记账号怎么办 忘记qq登录密码怎么办 崩坏3死邮怎么办 崩坏3死邮箱怎么办 手机邮箱文件打不开怎么办 户口注销后房产怎么办 公司注销后车辆怎么办 注销后的手机号怎么办 网易邮箱修复失败怎么办 网易邮箱忘记密码怎么办 苹果忘记安全问题答案怎么办 手机被黑客盯上怎么办 qq邮箱被占用怎么办 淘宝邮箱被占用怎么办 LOL出现上载错误怎么办 本科论文格式有些错误怎么办 下载的压缩包打不开怎么办