当我单击列表中的每个项目时,我需要获取项目的内容(图像和文本)

Posted

技术标签:

【中文标题】当我单击列表中的每个项目时,我需要获取项目的内容(图像和文本)【英文标题】:I need when I click in every item in the list I want to get the content of item (IMAGE AND TEXT) 【发布时间】:2018-08-27 10:13:35 【问题描述】:

我有一个列表视图的代码,,然后我需要将它们发送到包含(tabhost)的其他活动是我的代码:

listView.setOnItemClickListener(new AdapterView.OnItemClickListener() 
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int 
position, long id) 
            Intent intent = new Intent(Detail_Activity.this, 
            MoreDetailActivity.class);

            LayoutInflater mInflater = getLayoutInflater();
            View myView = mInflater.inflate(R.layout.detail_item, null);


            TextView txtid = (TextView) view.findViewById(R.id.tv_name);
            ImageView img = (ImageView) view.findViewById(R.id.img_id);
            String stg = txtid.getText().toString();



        
    );

【问题讨论】:

Getting Image from ImageView的可能重复 【参考方案1】:

试试这个

String stg = view.getText().toString();

这个 sn-p 展示了如何从列表视图中获取图像视图

 ImageView img = (ImageView) view.findViewById(R.id.img_id);
        final BitmapDrawable bitmapDrawable = (BitmapDrawable) img.getDrawable();
        final Bitmap yourBitmap = bitmapDrawable.getBitmap(); 
        img.setImageBitmap(yourBitmap);

希望对你有帮助!

【讨论】:

这是为了获取我知道的文本,但我怎样才能得到图像谢谢你 为图片添加 如何显示我在另一个活动中发送的图像

以上是关于当我单击列表中的每个项目时,我需要获取项目的内容(图像和文本)的主要内容,如果未能解决你的问题,请参考以下文章

Android:从自定义列表视图中单击的按钮获取列表视图项目

Recyclerview 根据单击的项目获取项目值

单击列表视图项目时,Android youtube api可全屏加载视频

滚动时列表的图标状态恢复

当我单击列表视图项目时,如何进入其他活动?

带有项目单击侦听器的列表视图在搜索视图中获取错误数据