第一种方法: 第一个界面传递(字符串和整数): btn_sendparam.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent=new Intent(MainActivity.this,Main2Activity.class); intent.putExtra("newtitle","安卓开发行情的新闻"); intent.putExtra("commentcount",135); startActivity(intent); } }); 第二个界面: String newsTitleString = getIntent().getStringExtra("newtitle"); int newsCount= getIntent().getIntExtra("commentcount",0); txt_showparamer.setText(newsTitleString); txt_showparamercount.setText(newsCount+"");
第二种方法:
第一个界面(利用bundle):
Intent intent=new Intent(MainActivity.this,Main2Activity.class); // intent.putExtra("newtitle","安卓开发行情的新闻"); // intent.putExtra("commentcount",135); // startActivity(intent); Bundle bundle=new Bundle(); bundle.putString("news_title","安卓开发行情的新闻"); bundle.putInt("comment_count",135); intent.putExtra("myBundle",bundle); startActivity(intent);
第二个界面:
Bundle bundle = getIntent().getBundleExtra("myBundle"); String news_titlestring = bundle.getString("news_title"); int count = bundle.getInt("comment_count"); txt_showparamer.setText(news_titlestring); txt_showparamercount.setText(count + "");