2012-12-03 105 views
1

我正在嘗試顯示一個用於顯示他已選擇的項的用戶的吐司消息。我已經在名單上走過了從一個另一個類的意圖,並在其代碼如下階級接受了它:在單擊可點擊列表時顯示列表視圖項選項

public class ListViewDelete extends ListActivity { 



@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    //setContentView(R.layout.activity_list_view_delete); 

    final Intent intent = getIntent(); 
    final Bundle extras = getIntent().getExtras(); //gets the GWID 

    final MySQLitehelper dbhelper = new MySQLitehelper(this); 
    ArrayList<String> thelist = new ArrayList<String>(extras.getStringArrayList(SelectOptions.EXTRA_MESSAGE)); 
    setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,extras.getStringArrayList(SelectOptions.EXTRA_MESSAGE))); 
}  

public void onListItemClick(ListView parent, View view, int position, long id) 
{ 
    Toast.makeText(this, "You have selected", Toast.LENGTH_LONG).show(); 
} 
} 

在過去onListItemClick,我該如何自定義了「您已選擇」後,我可以把上面定義的數組列表項的值?

public class ListViewDelete extends ListActivity { 

    private ArrayList<String> thelist; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     //setContentView(R.layout.activity_list_view_delete); 

     final Intent intent = getIntent(); 
     final Bundle extras = getIntent().getExtras(); //gets the GWID 

     final MySQLitehelper dbhelper = new MySQLitehelper(this); 
     thelist = new ArrayList<String>(extras.getStringArrayList(SelectOptions.EXTRA_MESSAGE)); 
     setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,extras.getStringArrayList(SelectOptions.EXTRA_MESSAGE))); 
    }  

    public void onListItemClick(ListView parent, View view, int position, long id) 
    { 
     Toast.makeText(this, "You have selected" + thelist.get(position), Toast.LENGTH_LONG).show(); 
    } 
} 

請注意,我所做的ArrayList的一個字段,以便能夠:

回答

1

,如果你有你的食指和ArrayList中,然後就可以通過索引來引用您的字符串集合中請參考其他方法。

+0

工作奇蹟。謝啦。你搖滾。 – noobcoder

2
public void onListItemClick(ListView parent, View view, int position, long id) 
{ 
Toast.makeText(this, "You have selected"+position, Toast.LENGTH_LONG).show(); 
} 
+1

這隻會給我索引。比如「你選擇了0」。我想要'thelist'變量中的實際字符串值。 – noobcoder

+0

String [] tmp =(String [])view.getItemAtPosition(position); – Venkat

相關問題