2011-03-13 38 views
0

这是我的第一类:如何从android中的另一个类获取文本?

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

二等:

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

我能够从图像的Firstclass传递到二级,但我不知道如何做到这一点的文字..请帮帮我 !!!

回答

0

创建一个包,即
例如,
Bundle myBundle = new Bundle();
myBundle.putInt(“pos”,position);
myBundle.putString(“mystring”,“your text”);
myIntent.putExtras(myBundle);
startActivityForResult(myIntent,0);

在secondActivity

捆绑额外= getIntent()getExtras();
int pos = extras.getString(“pos”);
String test = extras.getString(“mystring”);

这应该对你有所帮助。

1

尝试

myIntent.putExtra("key", "Text"); // in first class

getIntent().getExtras().getString("key"); // in second class

相关问题