在列表视图访问最后单击项目的形象 [英] Accessing image of the last clicked item in listview

查看:208
本文介绍了在列表视图访问最后单击项目的形象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是code为ListView适配器,它显示tracks.Each列表项的列表中的播放和停止的图标上播放图像按钮将变为暂停按钮图片和曲目开始播放和停止track.When用户点击playing..When我点击暂停按钮,图像将变为播放按钮图像和跟踪停止playing.While播放曲目,如果我点击另一个曲目播放图像按钮previous跟踪止损和当前曲目点击开始播放,但问题是previous轨道仍显示暂停图标图像按钮,而应该改变,因为目前播放的图像按钮,它不是playing.It是因为holder.img2可见性仍然是正确的,因为我们从来没有改变图像的可见性(holder.img1对于播放图标,holder.img2是停止图标)。对于我需要访问的最后单击项目的形象图标listview..What我应该怎么做才能让暂停图像按钮应该改变,如果播放的图像按钮I点击另一条轨道上的播放按钮,而玩当前的曲目。

Below is the code for the listview adapter which displays list of tracks.Each list item has play and stop icons to play and stop track.When user clicks on play image button it changes to pause button image and track starts playing..When I click on pause button image it changes to play button image and track stops playing.While playing a track if I click on another track play image button previous track stops and the current clicked track start playing but the issue is that previous track still show the pause icon image button while it should change to play image button since currently its not playing.It is because holder.img2 visiblity is still true since we never changed the visiblity of image( holder.img1 is for play icon and holder.img2 is for stop icon).For that i need to access the image icon of the last clicked item in listview..What should i do so that the pause image button should change to play image button if i clicked on another track play button while playing current track..

推荐答案

您可以使用这样的:


    的onClick
  • 保存位置在一个全局变量 lastPosition 每次

  • 检查位置不是默认值,然后获取其相关的行,它的图像,并设置自己的知名度为每个需要。

  • Save position in a global variable lastPosition in onClick every time.
  • Check if position is not default value, then get its related Row, its images, and set their visibility as per need.

int lastPosition = -1;

holder.img1.setOnClickListener(new View.OnClickListener()
{
    @Override
    public void onClick(final View v)
    {
        if (lastPosition != -1)  {
            View lastRow = listView.getChildAt(lastPosition);

            ImageView play = (ImageView) lastRow.findViewById(R.id.play2);
            ImageView pause = (ImageView) lastRow.findViewById(R.id.pause);
            play.setVisibility(View.GONE);
            pause.setVisibility(View.VISIBLE);
        }

    .. //all other code of onClick for media player
    lastPosition = position;
    }
}


希望它帮助。

这篇关于在列表视图访问最后单击项目的形象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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