![](/img/trans.png)
[英]How to pass data from a selected item in a listview to another activity?
[英]Pass selected item data from ListView from current activity to next activity
我有一個Custom ListView產品。 listview的每一行都包含產品名稱,圖像,價格和說明。 我想將listview的選定項目的標題,價格,描述和圖像從當前ListView活動傳遞到要顯示的下一個活動。 如何按意圖傳遞所選列表項的數據?
這是我的java文件中顯示列表的代碼的一部分:
private ArrayList<ThemeTourModel> GetThemeTourResults(){
ArrayList<ThemeTourModel> results = new ArrayList<ThemeTourModel>();
ThemeTourModel item_details = new ThemeTourModel();
item_details.settourname("Solo Woman Travellers");
item_details.settourDescription("Women searching the ultimate liberation may discover it in exploring the tourist destinations of world on their own. More freedom and security while traveling for leisurely getaways and adventures.");
item_details.setImageNumber(1);
item_details.setPrice("Rs.6999 - Rs.8999");
results.add(item_details);
return results;
}
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
// TODO Auto-generated method stub
if(position==0){
Intent i0 = new Intent(this,EnquireActivity.class);
startActivity(i0);
}
您可以通過intent.putExtra(name,value)
將通過Intent的原始數據放置到另一個活動中intent.putExtra(name,value)
並通過另一個Activity上的getIntent().getExtra()
獲取值。 您可以在此處找到參考: http : //developer.android.com/reference/android/content/Intent.html#putExtra (java.lang.String,android.os.Bundle)另一種方法是讓您的項目對象實現Parcelable
在活動之間進行交換,請查看以下內容: Android:如何對我的對象實現Parcelable? 。
希望這可以幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.