- 101
- 0
- 约1.8万字
- 约 14页
- 2020-01-21 发布于天津
- 举报
安卓开发实验报告
目录
页面跳转
长按图标抖动以及显示删除
页面跳转
功能:通过点击button实现2个activity之间的跳转。
1.设置监听器监听点击button
2.使用intent传输数据
完整代码
1.ui_test.java
public class UI_Test extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.incident_activity_1);
Button bt = (Button)findViewById(R.id.login);
bt.setOnClickListener(new OnClickListener());
}
class OnClickListener implements View.OnClickListener{
public void onClick(View v){
EditText name = (EditText)findViewById(R.);
EditText password = (EditText)findViewById(R.id.password);
Bundle data=new Bundle();
data.putString(name, name.getText().toString());
data.putString(password, password.getText().toString());
Intent intent = new Intent(UI_Test.this,UI_Result.class);
intent.putExtras(data);
startActivity(intent);
}
}
2.ui_result.java
public class UI_Result extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.incident_activity_2);
TextView name = (TextView)findViewById(R.Show);
TextView password = (TextView)findViewById(R.id.passwordShow);
Intent intent=getIntent();
Bundle result = intent.getExtras();
name.setText(您的用户名为: +result.getString(name));
password.setText(您的密码为: +result.getString(password));
}
}
3.activity_1.xml
?xml version=1.0 encoding=utf-8?
TableLayout xmlns:android=/apk/res/android
android:layout_width=fill_parent
android:layout_height=fill_parent
TextView
android:layout_width=fill_parent
android:layout_height=wrap_content
android:text=请输入您的信息
android:textSize=20sp
/
TableRow
android:id=@+id/tableRow1
android:layout_width=fill_parent
an
原创力文档

文档评论(0)