嗨,我有使用 Aquery 的复选框的歌曲列表视图,我无法在列表滚动时保存复选框的状态。我有两个arraylist,一个用于单击歌曲图像,另一个用于复选框,如果用户选择它应该根据复选框arraylist播放歌曲的复选框。我也用过这个 check.setChecked(SelectedBox.get(clickedposition).getisCheck()); . 但没有帮助
到目前为止我所做的是在这里
private void createList() {
listAq = new AQuery(this);
adapter = new ArrayAdapter<Audio>(SongList.this, R.layout.list_row,details) {
@Override
public View getView(final int position, View convertView,final ViewGroup parent) {
if (convertView == null) {
convertView = getLayoutInflater().inflate(R.layout.list_row, parent, false);
}
final int clickedposition = position;
final AQuery aq = listAq.recycle(convertView);
Audio item = getItem(position);
aq.id(R.id.MovieName).text(item.getAlbumName());
aq.id(R.id.SongName).text(item.getTitle());
aq.id(R.id.checkBox1).getCheckBox().setSelected(item.getisCheck());
aq.id(R.id.nameLayout).clicked(new OnClickListener() {
@Override
public void onClick(View v) {
DialogBuilder(position);
}
});
check = (CheckBox) convertView.findViewById(R.id.checkBox1);
check.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
try {
if (isChecked) {
checkbox = true;
if (details.get(clickedposition).getisCheck() == false) {
SelectedBox.add(details.get(clickedposition));
System.out.println(SelectedBox.size());
details.get(clickedposition).setisCheck(true);
}
} else {
final String name = details.get(clickedposition).getFilename();
for (int i = 0; i <= SelectedBox.size(); i++) {
if (name.equals(SelectedBox.get(i).getFilename())) {
SelectedBox.remove(i);
details.get(clickedposition).setisCheck(false);
}
}
}
notifyDataSetChanged();
}
catch (Exception e) {
e.getMessage();
}
}
});
try{
}
catch (Exception e) {
// TODO: handle exception
}
url = "drawable/" + item.getThumbnail();
imageResource = getResources().getIdentifier(url, null,getPackageName());
aq.id(R.id.song_image).image(imageResource);
if (position != playingValue) {
aq.id(R.id.imageplay).invisible();
aq.id(R.id.imageplay).getImageView().bringToFront();
} else {
aq.id(R.id.imageplay).visible();
}
ImageView img = (ImageView)convertView.findViewById(R.id.song_image);
img.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
checkbox = false;
SelectedBox.clear();
currentSongIndex = position;
try {
if (ChannelService.playerFlag == 0) {
playSong(currentSongIndex);
} else if ((ChannelService.playerFlag == 1)
|| ((ChannelService.playerFlag == 2))) {
if (currentSongIndex != playingValue) {
try {
final Intent serviceIntent = new Intent(
getApplicationContext(),
ChannelService.class);
stopService(serviceIntent);
mPlay.setBackgroundResource(R.drawable.play_btn);
playSong(currentSongIndex);
} catch (final IllegalStateException e) {
e.printStackTrace();
}
}
mPlay.setBackgroundResource(R.drawable.pause_btn);
final Intent in = new Intent("updateNotification");
sendBroadcast(in);
}
} catch (final IllegalStateException e) {
e.getMessage();
}
notifyDataSetChanged();
}
});
return convertView;
}
};
aq.id(R.id.listView1).adapter(adapter);
}