android studio 跳转传值

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="点击跳转"
android:layout_alignLeft="@+id/tv_title"
android:layout_marginLeft="90dp"
android:id="@+id/button"
android:onClick="skip"
/>
传值写法
public void skip(View view){
Intent intent = new Intent();
intent.setClass(MainActivity.this,SecondActivity.class);
Bundle bundle=new Bundle();
bundle.putString("id","完美二号");
intent.putExtras(bundle);
startActivity(intent);
}
跳转之后的界面
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="测试"
android:id="@+id/ceshi"
/>

</LinearLayout>

如何得到参数中得值
private String type="";
final Intent intent = getIntent();
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
Bundle bundle = this.getIntent().getExtras();
type=bundle.getString("id");
TextView textView=(TextView) findViewById(R.id.ceshi);
textView.setText(type);





}
posted @ 2018-11-19 14:55  轩钰儿  阅读(1472)  评论(0编辑  收藏  举报