作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个菜单 (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/
我正在尝试用 Swift 编写这段 JavaScript 代码:k_combinations 到目前为止,我在 Swift 中有这个: import Foundation import Cocoa e
我是一名优秀的程序员,十分优秀!