2011-12-31 55 views
0

我還在新的Android和有一個巨大的問題......Android的 - 從一個ListView發送INT指數多種活動

我有我周圍的商店String []數組一個ListViewActivity類。當用戶點擊其中任何一個時,我希望ListViewActivity將int索引發送到另一個活動(InfoActivity)。但是,在啓動InfoActivity之前,用戶將進入OptionsActivity,一旦他們點擊按鈕Info,他們就會被引導到InfoActivity。該索引將用於訪問此活動中另一個字符串[]數組中的項目。

我曾嘗試以下:

ListViewActivity:

Bundle newbundle = new Bundle(); 
newbundle.putInt("key", position); 
Intent intent = new Intent(ListViewActivity.this, InfoActivity.class); 
intent.putExtras(newbundle); 
startActivity(intent); 

startActivity(new Intent(ListViewActivity.this, OptionsActivity.class)); 

InfoActivity:

public class InfoActivity extends Activity{ 

String[] price1 = {"£46", "£44", "£45", "£43", "£47", "£45", "£48", "£42", "£46", "£43"}; 

int key; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
setContentView(R.layout.info); 

Bundle bundle = getIntent().getExtras(); 
key = bundle.getInt("key", 0); 

TextView price1 = (TextView)findViewById(R.id.hairprice11); 

price1.setText(hair_stylists_price1[key]); 

...

任何想法?

回答

1

試試這個..

Intent intent = new Intent(ListViewActivity.this, InfoActivity.class); 
intent.putExtra("key", position); 
startActivity(i); 

然後將其拉出..

int index = getIntent().getIntExtra("key"); 
相關問題