Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/220.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将所选项目的数据传递给另一个活动-android_Android_Android Arrayadapter_Custom Lists - Fatal编程技术网

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

将所选项目的数据传递给另一个活动-android,android,android-arrayadapter,custom-lists,Android,Android Arrayadapter,Custom Lists,我有一个菜单(FishComboValueFounds),,当用户选择多个项目时,我需要它们 要在另一个活动(购物车)的列表中显示项目,我已经尝试了很多,但数据不正确 从不出现在购物车中!单击按钮有什么问题吗, 我有 fishcombovaluemeal.java RowItem.java CustomListViewAdapter.java FishComboValueMealActivityCode: package com.example.newlist; public

我有一个菜单
(FishComboValueFounds),
,当用户选择多个项目时,我需要它们 要在另一个活动(购物车)的列表中显示项目,我已经尝试了很多,但数据不正确
从不出现在购物车中!单击
按钮有什么问题吗,
我有

fishcombovaluemeal.java  
RowItem.java  
CustomListViewAdapter.java  
FishComboValueMealActivityCode:

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);
        }


}
package com.example.newlist;
公共类fishComboValueFinds扩展了活动实现
麦克利克监听器{
图像按钮Ib2;
公共静态最终字符串[]标题=新字符串[]{
"鱼片(中价膳食),,
“鱼片(大餐)”,
“双鱼片(中餐)”,
“双鱼片(大餐)”,
};
公共静态最终字符串[]说明=新字符串[]{
“轻而薄的白鱼片,上面涂着浓烈的酒石”,
“轻而薄的白鱼片,上面涂着浓烈的酒石”,
“在一层奶酪上放两块嫩鱼片,”,
“2块嫩鱼片,铺在一层薄纱上”
};
公共静态最终整数[]图像={
R.drawable.imfc1,
R.drawable.imfc2,
R.drawable.imfc3,
R.drawable.imfc4};
公共静态最终双[]价格={20.0,22.73,24.77,27.04};
列表视图列表视图;
列出项目;
/**在首次创建活动时调用*/
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(右布局、活动和早餐);
rowItems=新的ArrayList();
对于(int i=0;i
您可以使用一个非常简单的类将数据存储到其中。 我警告你,这门课只是一个简单的命题,如何解决你的问题。 它有很多缺点,但它是有效的;) 您可以改进它:) 只需在应用程序类初始化它

下面是一个例子:

/**
 * Manager to handle passing data between Activities
 * 
 * @author Klawikowski
 * 
 */
public class ManagerBundle implements IConstants
{
    public static final String TAG = "ManagerBundle";

    private static Hashtable< Integer , Object > sDataTable;

    public static void init()
    {
        Log.i( TAG , "[ManagerBundle] Initializing ..." );
        sDataTable = new Hashtable< Integer , Object >();
    }

    public static void addBundle( int pKey , Object pObjectToPass )
    {
        Log.i( TAG , "[ManagerBundle] Adding Object to Manager using key: " + pKey );
        sDataTable.put( pKey , pObjectToPass );
    }

    public static Object getBundle( int pKey )
    {
        Log.i( TAG , "[ManagerBundle] Getting Object from Manager using key: " + pKey );
        Object lData = sDataTable.get( pKey );
        sDataTable.remove( pKey );
        return lData;
    }
}
/**
*经理处理活动之间的数据传递
* 
*@作者克拉维科夫斯基
* 
*/
公共类ManagerBundle实现IConstants
{
公共静态最终字符串TAG=“ManagerBundle”;
私有静态哈希表sDataTable;
公共静态void init()
{
Log.i(标记“[ManagerBundle]正在初始化…”);
sDataTable=新哈希表<整数,对象>();
}
公共静态void addBundle(int-pKey,对象pObjectToPass)
{
Log.i(标记“[ManagerBundle]使用键“+pKey”向管理器添加对象);
sDataTable.put(pKey,pObjectToPass);
}
公共静态对象getBundle(int-pKey)
{
Log.i(标记“[ManagerBundle]使用键“+pKey”从管理器获取对象);
对象lData=sDataTable.get(pKey);
sDataTable.remove(pKey);
返回lData;
}
}

只需在开始活动之前放置一个表/数组或任何其他容器,然后从第二个容器中收集;)

您可以使用一个非常简单的类将数据存储到其中。 我警告你,这门课只是一个简单的命题,如何解决你的问题。 它有很多缺点,但它是有效的;) 您可以改进它:) 只需在应用程序类初始化它

下面是一个例子:

/**
 * Manager to handle passing data between Activities
 * 
 * @author Klawikowski
 * 
 */
public class ManagerBundle implements IConstants
{
    public static final String TAG = "ManagerBundle";

    private static Hashtable< Integer , Object > sDataTable;

    public static void init()
    {
        Log.i( TAG , "[ManagerBundle] Initializing ..." );
        sDataTable = new Hashtable< Integer , Object >();
    }

    public static void addBundle( int pKey , Object pObjectToPass )
    {
        Log.i( TAG , "[ManagerBundle] Adding Object to Manager using key: " + pKey );
        sDataTable.put( pKey , pObjectToPass );
    }

    public static Object getBundle( int pKey )
    {
        Log.i( TAG , "[ManagerBundle] Getting Object from Manager using key: " + pKey );
        Object lData = sDataTable.get( pKey );
        sDataTable.remove( pKey );
        return lData;
    }
}
/**
*经理处理活动之间的数据传递
* 
*@作者克拉维科夫斯基
* 
*/
公共类ManagerBundle实现IConstants
{
公共静态最终字符串TAG=“ManagerBundle”;
私有静态哈希表sDataTable;
公共静态void init()
{
Log.i(标记“[ManagerBundle]正在初始化…”);
sDataTable=新哈希表<整数,对象>();
}
公共静态void addBundle(int-pKey,对象pObjectToPass)
{
Log.i(标记“[ManagerBundle]使用键“+pKey”向管理器添加对象);
sDataTable.put(pKey,pObjectToPass);
}
公共静态对象getBundle(int-pKey)
{
Log.i(标记“[ManagerBundle]使用键“+pKey”从管理器获取对象);
对象lData=sDataTable.get(pKey);
sDataTable.remove(pKey);
返回lData;
}
}
只需在开始活动之前放置一个表/数组或任何其他容器,然后从第二个容器中收集;)

你可以试试这个

@Override
public void onItemClick(AdapterView<?> parent, View   view, int position,
        long id) {
    RowItem selItem =  rowItems.get(position);//get the selected RowItem from the list
    String[] selValues= selItem.getMethodName();//your method name in RowItem.java class
                                                //which returns array  
    //if you have getter and setters you can access them and put them in array
    //String[] selArray = new String[size];//size = number of value you want to supply
    //String[0]= selItem.getTitle();//for title
    //String[1] = selItem.getDescription();//for description and so on
    //then send the array as parameter 

    // remaining is same as answered by the Jay Gajjar

    Bundle b=new Bundle();
    b.putStringArray("EXTRA", selArray);
    Intent i = new Intent(getApplicationContext(), ShoppingCart.class);
    i.putExtras(b);
    startActivity(i);
}
你可以试试这个

@Override
public void onItemClick(AdapterView<?> parent, View   view, int position,
        long id) {
    RowItem selItem =  rowItems.get(position);//get the selected RowItem from the list
    String[] selValues= selItem.getMethodName();//your method name in RowItem.java class
                                                //which returns array  
    //if you have getter and setters you can access them and put them in array
    //String[] selArray = new String[size];//size = number of value you want to supply
    //String[0]= selItem.getTitle();//for title
    //String[1] = selItem.getDescription();//for description and so on
    //then send the array as parameter 

    // remaining is same as answered by the Jay Gajjar

    Bundle b=new Bundle();
    b.putStringArray("EXTRA", selArray);
    Intent i = new Intent(getApplicationContext(), ShoppingCart.class);
    i.putExtras(b);
    startActivity(i);
}

您需要创建菜单项的单例数组。当用户执行multi-select jst时,将selectedindex存储到一个数组中,然后将该数组传递给intent

以下是多选列表视图的教程

下面是发送意图中的数组的代码

Bundle b=new Bundle();
b.putStringArray(key, new String[]{value1, value2});
Intent i=new Intent(context, Class);
i.putExtras(b);

Bundle b=this.getIntent().getExtras();
String[] array=b.getStringArray(key);

您需要创建菜单项的单例数组。当用户执行multi-select jst时,将selectedindex存储到一个数组中,然后将该数组传递给intent

以下是多选列表视图的教程

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