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);





}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM