-1
在我的应用程序中,我将值从page1传递给page2,并且工作正常。现在我想将这些值不仅从第1页发送到第2页,还发送到第3页。我怎样才能做到这一点?请帮我对此....如何在Android中将值从一个页面传递给其他页面?
第1页
public static final String CATEGORY_KEY = "category";
btn1.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(Page1.this,
Page2.class);
myIntent.putExtra(CATEGORY_KEY, "10");
startActivityForResult(myIntent, 0);
}
});
btn2.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(Page1.this,
Page2.class);
myIntent.putExtra(CATEGORY_KEY, "11");
startActivityForResult(myIntent, 0);
}
});
第2页
public static String catgryid;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageView type=(ImageView)findViewById(R.id.imageView1);
Intent intent = getIntent();
catgryid = intent.getStringExtra(Page1.CATEGORY_KEY);
if(catgryid.trim().equals("10"))
{
type.setBackgroundResource(R.drawable.img1);
}
else if(catgryid.trim().equals("11"))
{
type.setBackgroundResource(R.drawable.img2);
}
}
它不来了..你的意思是你得到空值做相同第1页? – 5hssba 2012-03-17 06:54:25
您是否在第2页获得了值 – 2012-03-17 06:59:38