Android学习第六天---activity2
2013-03-11 23:45
176 查看
主xml中
第二个页面的xml
java文件
第二个页面的activity
<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" tools:context=".MainActivity" > <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="用户名" /> <EditText android:id="@+id/username" android:layout_width="match_parent" android:layout_height="wrap_content"/> <TextView android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="用户密码" /> <EditText android:id="@+id/userpasswd" android:layout_width="match_parent" android:layout_height="wrap_content"/> <Button android:id="@+id/login" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/login" /> </LinearLayout>
第二个页面的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" tools:context=".MainActivity" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="~~~~" /> </RelativeLayout>
java文件
import java.io.Serializable; import java.util.ArrayList; import java.util.List; 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; public class MainActivity extends Activity implements OnClickListener{ EditText editText1,editText2; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); editText1=(EditText)findViewById(R.id.username); editText2=(EditText)findViewById(R.id.userpasswd); Button button=(Button)findViewById(R.id.login); button.setOnClickListener(this); } @Override public void onClick(View v) { String userName = editText1.getText().toString(); String userPasswd = editText2.getText().toString(); Intent intent = new Intent(); Bundle bundle = new Bundle(); bundle.putString("name", userName); bundle.putString("userpasswd",userPasswd); intent.putExtra("bundle", bundle); intent.setClass(MainActivity.this,SecondActivity.class); startActivity(intent); } }
第二个页面的activity
import java.util.List; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.widget.TextView; public class SecondActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.seconda_activity); TextView textView=(TextView)findViewById(R.id.textView1); Intent intent=this.getIntent(); Bundle bundle=intent.getBundleExtra("bundle"); String userName=(String)bundle.get("name"); String userPasswd=(String)bundle.get("userpasswd"); textView.setText(userName+"~~~"+userPasswd); } }
相关文章推荐
- Android学习第六天---progreessbar
- Java -Android 学习(第六天)
- Android学习第六天之组件篇初探Activity1.1
- Android学习第六天-碎片
- 学习android第六天
- Android学习第六天-JDB
- Android学习第六天---Activity
- 七、Android学习第六天——SQLite与文件下载(转)
- Android学习第六天---menu
- Android学习第六天---seekbar
- Android学习之简单使用SeekBar
- Scala学习第六天 Map、Tuple、Zip实战解析
- android jbox2d学习笔记一 滑轮关节
- Android 通知栏Notification的整合 全面学习
- Android开发学习之路--网络编程之初体验
- Android学习之——真机安装apk时出现INSTALL_FAILED_NO_MATCHING_ABIS错误的解决办法
- android游戏引擎andengine学习系列五:粒子发射器形成的超炫效果
- Android硬件抽象层(HAL)概要介绍和学习计划
- 【Android开发学习35】GL_TRIANGLE_STRIP之纹理贴图
- opencv 学习第六天 通道的分离