This is my First Class :
开发者_如何转开发public void onClick(View v) {
Intent myIntent = new Intent(v.getContext(),Second.class);
myIntent.putExtra("icon_image",mThumbIds[position]);
myIntent.putExtra("icon_text", categoryContent[position]);
startActivityForResult(myIntent, 0);
Second Class :
ImageView img=(ImageView)findViewById(R.id.icon_product);
int theID = getIntent().getExtras().getInt("icon_image");
img.setImageResource(theID);
TextView t1 = (TextView) findViewById(R.id.name_val);
I am able to pass images from FirstClass to Second Class , but i dont know how to do it for text .. PLease Help !!!
try
myIntent.putExtra("key", "Text"); // in first class
getIntent().getExtras().getString("key"); // in second class
Create a Bundle , i.e.
e.g.
Bundle myBundle = new Bundle();
myBundle.putInt("pos",position);
myBundle.putString("mystring","your text");
myIntent.putExtras(myBundle);
startActivityForResult(myIntent, 0);
In secondActivity
Bundle extras = getIntent().getExtras();
int pos = extras.getString("pos");
String test = extras.getString("mystring");
That should help you.
精彩评论