2011-11-27 65 views
0

我是android開發新手。我只想知道如何在我們正在導航的類中訪問變量(例如textview變量),以便我可以根據點擊的listview更改它的值。android listview and intent

這裏是一些代碼

protected void onListItemClick(ListView l, View v, int position, long id) { 
    // TODO Auto-generated method stub 
    super.onListItemClick(l, v, position, id); 



     Intent openStartingPoint = new Intent("com.name.MainClass"); 

     startActivity(openStartingPoint);} 

感謝

回答

2

最強大的這樣做的方法是把信息的意圖。

更改爲

Intent openStartingPoint = new Intent(this, com.name.MainClass.class); 
    openStartingPoint.putExtra("position", position); 
    startActivity(openStartingPoint);} 

,並在recieving活動的onCreate你寫:

Intent openStartingPoint = getIntent(); 
    int position = openStartingPoint.getIntExtra("position");