![](/img/trans.png)
[英]How to pass data from 2nd activity to 1st activity when pressed back? - android
[英]Pass the value from 1st activity to 2nd activity in android
我正在第一次活動的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);
}
};
在這里我要點擊一篇文章意味着文章名稱只傳遞給下一個活動並顯示該文章標題..我該怎么辦? 請給我這些解決方案???
如果你想使用意圖:
而去ListActivity傳遞數據...
intent.putExtra("Title", yourstring);
intent.putExtra("Content", yourstring);
startActivity(intent);
並在第二次活動使用中恢復它:
title= getIntent().getExtras().getString("Title");
...等等..
//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");
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");
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.