我正在第一次活动的textview上获得文章标题。我可以将这些textview传递给下一个活动......
我使用了以下代码:
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);
}
};
这里我要点击一篇文章意味着文章名称只传递给下一个活动并显示该文章标题..我该怎么办?请给我解决这些???
答案 0 :(得分:2)
如果你想使用意图:
进入ListActivity传递数据..
intent.putExtra("Title", yourstring);
intent.putExtra("Content", yourstring);
startActivity(intent);
并在第二次活动中恢复它:
title= getIntent().getExtras().getString("Title");
......等等..
答案 1 :(得分:1)
//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");
答案 2 :(得分:0)
public void onClick(View view)
{
public void run()
{
Intent i=new Intent(activity1.this,activity2.class);
i.putExtra("somename", variable1);
i.putExtra("somename1", variable2);
}
}
在第二项活动中
Bundle extras = getIntent().getExtras();
if (extras != null) {
one= extras.getDouble("somename");
two = extras.getDouble("somename2");
}