我找不到问题,无论何时我滚动视图都会改变.pls帮助我...我认为android回收查看如何覆盖?
1.在滚动之前 2.AFTER SCROLLING
public class MobileArrayAdapter extends ArrayAdapter<String> {
private final Context context;
private final String[] values;
private LayoutInflater inflater;
public MobileArrayAdapter(Context context, String[] values) {
super(context, R.layout.list_mobile, values);
inflater = LayoutInflater.from(context);
this.context = context;
this.values = values;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View rowView=convertView;
if (rowView == null) {
rowView = inflater.inflate(R.layout.list_mobile, null);
ViewHolder viewHolder = new ViewHolder();
viewHolder.text = (TextView) rowView.findViewById(R.id.label);
viewHolder.button = (ImageView) rowView
.findViewById(R.id.logo);
rowView.setTag(viewHolder);
}
ViewHolder holder = (ViewHolder) rowView.getTag();
String s = values[position];
holder.text.setText(s);
if (mp.isPlaying()) {
holder.imageView.setImageResource(R.drawable.stop);
} else {
holder.imageView.setImageResource(R.drawable.play);
}
return rowView;
}static class ViewHolder {
public TextView text;
public ImageView button;
}
}
主要活动中的
protected void onListItemClick(ListView l, View v, int pos, long id) {
if(mp.isPlaying() && itemno == pos){
mp.pause();
playing= true;
ListMobileActivity.this. imageView.setImageResource(R.drawable.play);
}
else if (playing=true && itemno== pos){
mp.start();
playing=false;
ListMobileActivity.this.imageView.setImageResource(R.drawable.stop);
}
if (mp.isPlaying()&& itemno!=pos){
ListMobileActivity.this.imageView.setImageResource(R.drawable.play);
}
if (itemno!=pos)
{
imageView = (ImageView)v. findViewWithTag(pos);
playSample(pos);
}
ListMobileActivity.this.itemno=pos;
//Variable i, here, is from a for loop.
}
private void playSample( int position)
{
AssetFileDescriptor afd = getApplicationContext().getResources().openRawResourceFd(songs[position]);
try{
if(mp.isPlaying())
ListMobileActivity. this.mp.stop();
ListMobileActivity. this.mp.reset();
ListMobileActivity. this.mp.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getDeclaredLength());
ListMobileActivity. this.mp.prepare();
ListMobileActivity. this. imageView.setImageResource(R.drawable.stop);
ListMobileActivity.this. mp.setOnCompletionListener(new OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
ListMobileActivity. this. imageView.setImageResource(R.drawable.play);
}
});
ListMobileActivity. this. mp.start();
afd.close();
}
catch (IllegalArgumentException e)
{
Log.e(TAG, "Unable to play audio queue do to exception: " + e.getMessage(), e);
}
catch (IllegalStateException e)
{
Log.e(TAG, "Unable to play audio queue do to exception: " + e.getMessage(), e);
}
catch (IOException e)
{
Log.e(TAG, "Unable to play audio queue do to exception: " + e.getMessage(), e);
}
}
答案 0 :(得分:0)
我认为您在列表项中使用自定义布局。
现在发生的情况是,当您使用自定义布局时,它会使布局膨胀,并且它将再次用于下一个项目。
因为自定义适配器的获取视图中的检查条件与此类似。
if(Song2.isplaying)
{
imgView.setImage(pauseimage);
}
else
{
imgView.setImage(playimage);
}
它适合你。
(它只是代码逻辑表示,因此需要由您设置检查标准。)
答案 1 :(得分:0)
1.您在使用array[]
进行列表视图展示,并尝试同时展示ImageView
String s = values[position];
holder.text.setText(s);
2.首先检查setImage的值
if (s.startsWith("al")) {
holder.image.setImageResource(R.drawable.baloon);
} else {
holder.image.setImageResource(R.drawable.pause);
}
3.否则你应该制作一个客户端适配器