gpt4 book ai didi

android - 滚动时带有按钮随机选择的 ListView 项目

转载 作者:行者123 更新时间:2023-11-29 01:50:53 25 4
gpt4 key购买 nike

<分区>

我在滚动时遇到奇怪的 ListView 项目选择。

初始选择截图(选择第一个条目) enter image description here

滚动 ListView 项目后自动选择为什么? (见下方截图)

enter image description here

适配器源代码是 here

public View getView(int position, View convertView, ViewGroup parent) {
View vi=convertView;
if(convertView==null)
vi = inflater.inflate(R.layout.list_row, null);

TextView title = (TextView)vi.findViewById(R.id.title); // title
TextView artist = (TextView)vi.findViewById(R.id.artist); // artist name
TextView duration = (TextView)vi.findViewById(R.id.duration); // duration
ImageView thumb_image=(ImageView)vi.findViewById(R.id.list_image); // thumb image

HashMap<String, String> song = new HashMap<String, String>();
song = data.get(position);

// Setting all values in listview
title.setText(song.get(CustomizedListView.KEY_TITLE));
artist.setText(song.get(CustomizedListView.KEY_ARTIST));
duration.setText(song.get(CustomizedListView.KEY_DURATION));
imageLoader.DisplayImage(song.get(CustomizedListView.KEY_THUMB_URL), thumb_image);
return vi;
}

让按钮在 setonitemclicklistner() 中可见是出了问题

list.setOnItemClickListener(new OnItemClickListener() {

@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
view.setSelected(true);
view.setBackgroundResource(R.drawable.gradient_bg_hover);
TextView title;
TextView artist;
title = (TextView)view.findViewById(R.id.title); // title
artist = (TextView)view.findViewById(R.id.artist); // artist
title.setTextColor(getResources().getColor(android.R.color.white));
artist.setTextColor(getResources().getColor(android.R.color.white));

ImageButton btnChild = (ImageButton)view.findViewById(R.id.arrow);
btnChild.setVisibility(View.VISIBLE);

if(lastselected!= null)
{

title = (TextView)lastselected.findViewById(R.id.title); // title
artist = (TextView)lastselected.findViewById(R.id.artist); // artist
title.setTextColor(getResources().getColor(android.R.color.black));
artist.setTextColor(getResources().getColor(android.R.color.black));

btnChild = (ImageButton)lastselected.findViewById(R.id.arrow);
btnChild.setVisibility(View.INVISIBLE);
lastselected.setBackgroundResource(R.drawable.gradient_bg);
}

lastselected= view;

图像按钮可见后,getview 为下一个显示项目回收相同的 View 。我不知道如何解决这个问题。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com