gpt4 book ai didi

android - 将所选项目的数据传递给另一个 Activity - android

转载 作者:行者123 更新时间:2023-11-30 03:32:43 25 4
gpt4 key购买 nike

我有一个菜单 (fishcombovaluemeals), 当用户选择超过 1 个项目时我想要那些 出现在另一个 Activity 列表中的项目(购物车),我已经尝试了很多但数据
永远不会出现在购物车中! onitemclick 出了什么问题!? , 我有

fishcombovaluemeal.java  
RowItem.java
CustomListViewAdapter.java

fishcombovaluemeals Activity 代码:

package com.example.newlist;

public class FishComboValueMeals extends Activity implements
OnItemClickListener {
ImageButton Ib2;
public static final String[] titles = new String[] {
" Fillet-O-Fish (Medium Value Meals) ",
"Fillet-O-Fish (Large Value Meals) ",
"Double Fillet-O-Fish (Medium Value Meals)",
" Double Fillet-O-Fish (Large Value Meals) ",

};




public static final String[] descriptions = new String[] {
"Light, flaky filet of white fish topped with tangy tartar ",
"Light, flaky filet of white fish topped with tangy tartar ",
"2 patties of tender fish filet over a layer of cheese, ",
" 2 patties of tender fish filet over a layer of "

};
public static final Integer[] images = {
R.drawable.imfc1,
R.drawable.imfc2,
R.drawable.imfc3,
R.drawable.imfc4 };



public static final Double[] prices = { 20.0, 22.73, 24.77, 27.04 };

ListView listView;
List<RowItem> rowItems;


/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_breakfast);


rowItems = new ArrayList<RowItem>();
for (int i = 0; i < titles.length; i++) {
RowItem item = new RowItem (images[i], titles[i], descriptions[i],
prices[i]);
rowItems.add(item);
}
listView = (ListView) findViewById(R.id.list);
CustomListViewAdapter adapter = new CustomListViewAdapter(this,
R.layout.list_item, rowItems);
listView.setAdapter(adapter);
listView.setOnItemClickListener(this);


Ib2 = (ImageButton) findViewById (R.id.Button02);


Ib2.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View arg0) {
// TODO Auto-generatedmethod stub
Intent openStartingPoint = new Intent (getApplicationContext(),ShoppingCart.class);


startActivity (openStartingPoint);

}
});}



@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {

Intent i = new Intent(getApplicationContext(), ShoppingCart.class);

i.putExtra("EXTRA", "Item " + (position + 1) + ": " + rowItems.get(position));
startActivity(i);
}


}

最佳答案

获取 ListView 的选中项并通过intent发送值

@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
String value = lv1.getItemAtPosition(position).toString();
Intent i = new Intent(getApplicationContext(), ShoppingCart.class);
i.putExtra("EXTRA", value);
startActivity(i);
}

并在其他 Activity 中获取值(value)

Bundle bundle=getIntent().getExtras();
String value=bundle.getString("EXTRA");

关于android - 将所选项目的数据传递给另一个 Activity - android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17167674/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com