开发者

How to get the text from another class in android?

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜