Activity跳转中在Activity传值
来源:互联网 发布:js创建tr 编辑:程序博客网 时间:2024/06/01 14:42
具体例题在360云盘中http://yunpan.cn/cZNcQw3cf3Spb 访问密码 9d90
清单文件同样需要注册Activity
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"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:textSize="28sp"
android:textColor="#ff0000"
android:text="人品测试" />
<EditText
android:id="@+id/et_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入姓名:" />
<Button
android:id="@+id/test"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="开始测试" />
</LinearLayout>
主Java文件
public class MainActivity extends Activity implements OnClickListener {
private EditText et_name ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout. activity_main);
Button test = (Button) findViewById(R.id.test);
et_name= (EditText) findViewById(R.id. et_name);
test.setOnClickListener( this);
}
@Override
public void onClick(View v) {
String name= et_name.getText().toString().trim();
if(TextUtils.isEmpty(name)){
new AlertDialog.Builder(this).setMessage("名字不能为空").show();
}
else{
Intent intent = new Intent(this , ResultActivity.class);
intent.putExtra( "name",name);
startActivity(intent);
}
}
}
副xml文件
<?xml version= "1.0" encoding ="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width= "match_parent"
android:layout_height= "match_parent"
android:orientation= "vertical" >
<TextView
android:layout_width= "wrap_content"
android:layout_height= "wrap_content"
android:textSize= "28sp"
android:textColor= "#ff0000"
android:text= "你的人品值"
android:layout_gravity= "center_horizontal"/>
<TextView
android:id="@+id/tv_result"
android:layout_width= "match_parent"
android:layout_height= "wrap_content"
/>
<ProgressBar
android:id="@+id/pb_testRP"
style= "?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:max="100" />
</LinearLayout>
副Java文件
public class ResultActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout. result);
TextView result =(TextView) findViewById(R.id. tv_result);
Intent intent = getIntent();
String name= intent.getStringExtra( "name");
Random random = new Random();
int rp = random.nextInt(101);
result.setText(name+ "您的人品值为:" +rp);
ProgressBar pb = (ProgressBar) findViewById(R.id. pb_testRP);
pb.setProgress(rp);
}
}
0 0
- Activity跳转中在Activity传值
- 在PreferenceScreen中添加跳转Activity
- menu中 跳转Activity
- Android中Activity跳转
- android在adapter中调用activity跳转效果
- 在activity中调用finish后并不是立马跳转
- 运用Intent在不同Activity中跳转tips
- 老罗安卓教程 在TextView文本中跳转到Activity
- 在listview adapter的控件中跳转activity
- 在同一个Activity中fragment之间的跳转!
- 如何在非Activity类中跳转到其他Activity类中
- android中在一个Activity中停留几秒后跳转至另外一个Activity
- Android中Activity跳转问题
- android中Activity的跳转
- Android中Activity跳转问题
- Android中Activity的跳转
- Android 中 Activity的跳转
- 在Activity的oncreate方法中如果跳转到别的activity,会发生什么
- 在Anandroid中如何开启另外界面,获取另外界面的返回值
- P51 第17题 输出2-n之间的所有素数,n由键盘输入
- ubuntu支持qt程序
- javascript原型的修改与重写(覆盖)差别
- 信号量函数(semget、semop、semctl)及其范例
- Activity跳转中在Activity传值
- EasyCamera--更简单更灵活的相机应用编写
- Optimal Milking
- Android中读取联系人
- Win8+VS2012(32位)下编译x265
- 写篇笔记介绍markdown(2)(
- 关于C++多态性的一些总结
- Linux下修改fstab文件造成系统无法启动解决
- 黑马程序员——装饰类和继承类的区别