问题
As am getting article title on textview on first activity.how can i pass these textview to next activity...
I have used below code:
for ( j = 0; j <Appscontent.Sub_arraylisttwo.size(); j++)
{
LinearLayout ly = new LinearLayout(this);
ly.setOrientation(LinearLayout.VERTICAL);
ly.setOnClickListener(mArticleClick);
TextView tv = new TextView(this);
tv.setText(Appscontent.Sub_arraylisttwo.get(j));
ly.addView(tv);
lLayout.addView(ly);
}
int num=Integer.parseInt(number);
number=String.valueOf(num=num+1);
System.out.println("the Number Value Is"+number);
Appscontent.Sub_arraylisttwo.clear();
hSroll.addView(lLayout);
viewLayout.addView(headerText);
viewLayout.addView(hSroll);
verticalLayout.addView(viewLayout);
Log.i("12", "" + lLayout.getChildCount());}
}
private OnClickListener mArticleClick = new OnClickListener() {
@Override
public void onClick(View v) {
Intent in = new Intent(MainActivity.this, SubCate.class);
startActivity(in);
}
};
Here i have to click one article means that article name only pass to next activity and display that article title.. how can i do ??? please give me solution for these ???
回答1:
if you want to use intents:
while going to the ListActivity pass data by..
intent.putExtra("Title", yourstring);
intent.putExtra("Content", yourstring);
startActivity(intent);
and to recover it in second activity use:
title= getIntent().getExtras().getString("Title");
...and so on..
回答2:
//to pass :
Intent in = new Intent(MainActivity.this, SubCate.class);
in.putExtra("name", "Artical Name");
startActivity(in);
// to retrieve object in second Activity
getIntent().getSerializableExtra("name");
回答3:
public void onClick(View view)
{
public void run()
{
Intent i=new Intent(activity1.this,activity2.class);
i.putExtra("somename", variable1);
i.putExtra("somename1", variable2);
}
}
In the second activity
Bundle extras = getIntent().getExtras();
if (extras != null) {
one= extras.getDouble("somename");
two = extras.getDouble("somename2");
}
来源:https://stackoverflow.com/questions/15173134/pass-the-value-from-1st-activity-to-2nd-activity-in-android