如何从android中的另一个类获取文本?
这是我的第一节课:如何从android中的另一个类获取文本?,android,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]); startActivityFo
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);
我能够将图像从一级传递到二级,但我不知道如何将其用于文本。。请帮忙 创建一个捆绑包,即e、 g.
Bundle myBundle=新Bundle()
myBundle.putInt(“位置”,位置)
putString(“mystring”,“您的文本”)
myIntent.putExtras(myBundle)
startActivityForResult(myIntent,0) 在第二次活动中 Bundle extras=getIntent().getExtras()
int pos=extras.getString(“pos”)
字符串测试=extras.getString(“mystring”) 这对你应该有帮助。试试看
myIntent.putExtra(“键”、“文本”);//头等舱
getIntent().getExtras().getString(“键”);//二等舱