如何通过从所选项目的数据在ListView到另一个活动? [英] How to pass data from a selected item in a listview to another activity?

查看:107
本文介绍了如何通过从所选项目的数据在ListView到另一个活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的code。我有0 的对象中的数据。有在三组值0 (描述,名称,图像URL)。我需要这些数据被初始化为字符串,并使用它的意图传递给其他活动。如何获取对象中的每个值。每个列表项目都有一个形象,项目名称和项目描述。

  fp_list.setOnItemSelectedListener(新OnItemSelectedListener(){
    @覆盖
    公共无效onItemSelected(适配器视图parentView,视图V,INT位置,长的id){
        // TODO自动生成方法存根
        Toast.makeText(getApplicationContext(),POS+位置,Toast.LENGTH_LONG).show();
        对象o = parentView.getItemAtPosition(位置);
        意图I =新意图(FeaturedProductsActivity.this,ShowProduct.class);
    }
}


解决方案

 捆绑包=新包();                bundle.putString(memId,o.getId());
                意图newIntent =新意图(friendsOffrinends.this,RestaurantDetails.class);
                newIntent.putExtras(包);
                startActivityForResult(newIntent,0);

I have the following code. I have the data in the object o. There are three set of values in o (description, name, image url). I need these data to be initialized to a string and pass it to other activity using intent. How do I get each value in the object. Each list item has a image, item name and item description.

fp_list.setOnItemSelectedListener(new OnItemSelectedListener() {
    @Override
    public void onItemSelected(AdapterView parentView, View v, int position, long id) {
        // TODO Auto-generated method stub
        Toast.makeText(getApplicationContext(), "pos"+position, Toast.LENGTH_LONG).show();
        Object o = parentView.getItemAtPosition(position);
        Intent i = new Intent(FeaturedProductsActivity.this, ShowProduct.class);
    }
}

解决方案

      Bundle bundle =new Bundle();

                bundle.putString("memId",o.getId() );
                Intent newIntent=new Intent(friendsOffrinends.this,RestaurantDetails.class);
                newIntent.putExtras(bundle);
                startActivityForResult(newIntent, 0);

这篇关于如何通过从所选项目的数据在ListView到另一个活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆