由于我要做的是点击后对改控件做旋转处理,点击完后旋转是做了,下拉又发现其他item也跟着旋转了
求大牛帮帮忙啊,小弟感激不尽,在线急等啊
21 个解决方案
#1
这个是convertView重用的结果,用map把控件旋转的状态保持起来,在getView里面根据这个状态设置控件。
#2
我也遇到过这种情况,我的listview上下拖动时原先响应的控件乱了,我认为应该是没记录响应控件的ID吧,我的解决方法是自定义了一个adapter,在里面写了一个数组记录每次响应控件的ID
#3
麻烦您可不可以再详细点?
#4
自己顶下,寻求更多帮帮助
#5
你把代码贴下,估计是逻辑有问题
#6
package com.sweetsopt.showeat.ui.adapter;
import java.util.HashMap;
import java.util.List;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.DecelerateInterpolator;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.dblife.frwe.anim.Rotate3dAnimation;
import com.dblife.frwe.utils.ImageUtils;
import com.dblife.frwe.utils.L;
import com.dblife.frwe.utils.PhoneUtils;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.sweetsopt.showeat.ui.ParamsHelper;
import com.sweetsopt.showeat.ui.bean.item.ShowtimeItemInfo;
import com.sweetspot.showeat.R;
/**
* <b>ClassName</b> FoodieShowPlusListAdatpter.java<br>
*
* <b>BuildTime:</b> 2015年1月4日<br>
* <b>Author:</b> Curzbin<br>
*
* <b>UpdateTime:</b> <br>
* <b>UpdateUser:</b> <br>
*
* <b>Description:</b> <br>
*/
public class FoodieShowPlusListAdatpter extends BaseAdapter{
private List<ShowtimeItemInfo> list;
private LayoutInflater mInflater;
private DisplayImageOptions options;
private HashMap<Integer, View> rlyMap = new HashMap<Integer, View>();
private HashMap<Integer, View> txvMap = new HashMap<Integer, View>();
public FoodieShowPlusListAdatpter(LayoutInflater mInflater, List<ShowtimeItemInfo> list) {
this.list = list;
this.mInflater = mInflater;
options = new DisplayImageOptions.Builder()
.showImageForEmptyUri(R.color.gray_level_2)
.showImageOnFail(R.color.gray_level_3)
.cacheInMemory(true)
.cacheOnDisk(true)
.resetViewBeforeLoading(true)
.considerExifParams(true)
.build();
}
@Override
public int getCount() {
return list.size();
}
@Override
public Object getItem(int position) {
return list.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.item_foodie_show_list_plus, parent, false);
holder = new ViewHolder();
holder.rlyCover = (RelativeLayout) convertView.findViewById(R.id.fsp_imgs);
holder.imgFsp = (ImageView) convertView.findViewById(R.id.fsp_cover);
holder.imgUserIcon = (ImageView) convertView.findViewById(R.id.fsp_usericon);
holder.txvContent = (TextView) convertView.findViewById(R.id.fsp_content);
holder.btnFavor = (ImageButton) convertView.findViewById(R.id.btn_favor);
holder.btnComment = (ImageButton) convertView.findViewById(R.id.btn_comment);
holder.btnCollect = (ImageButton) convertView.findViewById(R.id.btn_collection);
holder.btnShare = (ImageButton) convertView.findViewById(R.id.btn_share);
ImageUtils.setImageViewSize(holder.imgFsp, 4, 3);
ImageUtils.setImageViewSize(holder.txvContent, 4, 3);
rlyMap.put(position, holder.rlyCover);
txvMap.put(position, holder.txvContent);
convertView.setTag(holder);
holder.rlyCover.setOnClickListener(new OnRotateClickListener(position));
holder.txvContent.setOnClickListener(new OnRotateClickListener(position));
} else {
holder = (ViewHolder) convertView.getTag();
}
String urlContent = ParamsHelper.checkUrl(list.get(position).getPhoto());
String urlIcon = ParamsHelper.checkUrl(list.get(position).getUserphoto());
ImageLoader.getInstance().displayImage(urlIcon, holder.imgUserIcon, options);
ImageLoader.getInstance().displayImage(urlContent, holder.imgFsp, options);
holder.txvContent.setText(list.get(position).getContent());
return convertView;
}
public class OnRotateClickListener implements OnClickListener {
private View rotate1, rotate2;
float X = PhoneUtils.getScreenWidth() / 2;
float Y = PhoneUtils.getScreenHeight() / 2;
float Z = 20;
float localX = 0, localY = 0, localZ = -20;
int mDuration = 300, position;
public OnRotateClickListener(int position) {
this.rotate1 = rlyMap.get(position);
this.rotate2 = txvMap.get(position);
this.position = position;
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
L.i(position);
if (rotate1.getVisibility() == View.VISIBLE) {
applyRotation(rotate1, 1);
} else if (rotate2.getVisibility() == View.VISIBLE) {
applyRotation(rotate2, 2);
}
}
/**
*
* <b>Description:</b> <br>
*
* @param animView
*/
private void applyRotation(View animView, int page) {
Rotate3dAnimation rotation = new Rotate3dAnimation(0, 90, X, Y, Z, true);
rotation.setDuration(mDuration);
rotation.setFillAfter(true);
rotation.setCameraLocation(localX, localY, localZ);
rotation.setInterpolator(new AccelerateInterpolator());
rotation.setAnimationListener(new DisplayNextView(animView, page));
animView.startAnimation(rotation);
}
/**
* This class listens for the end of the first half of the animation. It
* then posts a new action that effectively swaps the views when the
* container is rotated 90 degrees and thus invisible.
*/
private final class DisplayNextView implements Animation.AnimationListener {
private int page;
public DisplayNextView(View view, int page) {
this.page = page;
}
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
if (page == 1) {
rotate1.setVisibility(View.INVISIBLE);
rotate2.setVisibility(View.VISIBLE);
rotate2.requestFocus();
Rotate3dAnimation rotation = new Rotate3dAnimation(-90, 0, X, Y, Z, false);
rotation.setDuration(mDuration);
rotation.setCameraLocation(localX, localY, localZ);
rotation.setFillAfter(true);
rotation.setInterpolator(new DecelerateInterpolator());
rotate2.startAnimation(rotation);
} else if (page == 2) {
rotate2.setVisibility(View.INVISIBLE);
rotate1.setVisibility(View.VISIBLE);
rotate1.requestFocus();
Rotate3dAnimation rotation = new Rotate3dAnimation(-90, 0, X, Y, Z, false);
rotation.setDuration(mDuration);
rotation.setCameraLocation(localX, localY, localZ);
rotation.setFillAfter(true);
rotation.setInterpolator(new DecelerateInterpolator());
rotate1.startAnimation(rotation);
}
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
}
}
/**
* Update data set
*
* @param list
*/
public void updateDataSet(List<ShowtimeItemInfo> list) {
this.list = list;
notifyDataSetChanged();
}
/**
* Add data set
*
* @param list
* a list of {@link ShowtimeItemInfo}
*/
public void addDataSet(List<ShowtimeItemInfo> list) {
this.list.addAll(list);
notifyDataSetChanged();
}
/**
* Add a data into list
*
* @param item
* object of {@link ShowtimeItemInfo}
*/
public void addOneData(ShowtimeItemInfo item) {
this.list.add(item);
notifyDataSetChanged();
}
/**
* update favorite number in ui
*
* @param favornum
* @param idx
*/
public void updateFavornum(String favornum, String idx) {
for (ShowtimeItemInfo item : list) {
if (item.getIdx().equals(idx)) {
item.setFavournum(favornum);
notifyDataSetChanged();
break;
}
}
}
private static class ViewHolder {
RelativeLayout rlyCover;
ImageView imgFsp, imgUserIcon;
TextView txvContent;
ImageButton btnFavor, btnShare, btnComment, btnCollect;
}
/**
* Show time buttons click listener
* @author FnsyBao
*
*/
public interface ShowTimeClickListener {
public void onFavorClick(String idx);
public void onCommentClick(String idx);
public void onShareClick();
public void onCollectionClick();
public void onFavorListClick(String idx);
}
/**
* To avoid overwrite too much function , <br>
* this adapter implements {@link ShowTimeClickListener}
* @author FnsyBao
*
*/
public class ShowTimeClickListenerAdapter implements ShowTimeClickListener {
@Override
public void onFavorClick(String idx) {}
@Override
public void onCommentClick(String idx) {}
@Override
public void onShareClick() {}
@Override
public void onCollectionClick() {}
@Override
public void onFavorListClick(String idx) {}
}
}
#7
holder.rlyCover.setOnClickListener(new OnRotateClickListener(position));
holder.txvContent.setOnClickListener(new OnRotateClickListener(position));这两句话 要写在逻辑外面
holder.txvContent.setOnClickListener(new OnRotateClickListener(position));这两句话 要写在逻辑外面
#8
写在if...else...外面吗?没用啊
#9
应该有用啊,你写在里面是把每个控件都绑定了点击事件,你debug看看,每次点击的时候执行了什么
#10
rlyMap.put(position, holder.rlyCover);
txvMap.put(position, holder.txvContent);
这个的位置也有问题,而且你这样用也不太好啊。
直接在OnRotateClickListener构造的时候传递个holder就行了,干什么还要那么麻烦存到HashMap中。
#11
debug的时候是跑了一遍onClick里面的内容,只有一遍,但是还是有别的item内容翻转了
#12
去了hashmap直接传holder也是一样的结果
#13
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.item_foodie_show_list_plus, parent, false);
holder = new ViewHolder();
holder.rlyCover = (RelativeLayout) convertView.findViewById(R.id.fsp_imgs);
holder.imgFsp = (ImageView) convertView.findViewById(R.id.fsp_cover);
holder.imgUserIcon = (ImageView) convertView.findViewById(R.id.fsp_usericon);
holder.txvContent = (TextView) convertView.findViewById(R.id.fsp_content);
holder.btnFavor = (ImageButton) convertView.findViewById(R.id.btn_favor);
holder.btnComment = (ImageButton) convertView.findViewById(R.id.btn_comment);
holder.btnCollect = (ImageButton) convertView.findViewById(R.id.btn_collection);
holder.btnShare = (ImageButton) convertView.findViewById(R.id.btn_share);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
ImageUtils.setImageViewSize(holder.imgFsp, 4, 3);
ImageUtils.setImageViewSize(holder.txvContent, 4, 3);
rlyMap.put(position, holder.rlyCover);
txvMap.put(position, holder.txvContent);
holder.rlyCover.setOnClickListener(new OnRotateClickListener(position));
holder.txvContent.setOnClickListener(new OnRotateClickListener(position));
String urlContent = ParamsHelper.checkUrl(list.get(position).getPhoto());
String urlIcon = ParamsHelper.checkUrl(list.get(position).getUserphoto());
ImageLoader.getInstance().displayImage(urlIcon, holder.imgUserIcon, options);
ImageLoader.getInstance().displayImage(urlContent, holder.imgFsp, options);
holder.txvContent.setText(list.get(position).getContent());
return convertView;
}
这样试试,如果还有问题,就等看看给OnRotateClickListener是不是有问题了
#14
一开始就是这样有问题我才把onClickListener拉到if里面试试的
#15
那就是OnRotateClickListener里面获取的控件有问题,直接传holder.
rlyMap.put(position, holder.rlyCover);
txvMap.put(position, holder.txvContent);
holder.rlyCover.setOnClickListener(new OnRotateClickListener(position));
holder.txvContent.setOnClickListener(new OnRotateClickListener(position));
改成
holder.rlyCover.setOnClickListener(new OnRotateClickListener(holder));
holder.txvContent.setOnClickListener(new OnRotateClickListener(holder));
holder也改下
public class OnRotateClickListener implements OnClickListener {
private View rotate1, rotate2;
...
public OnRotateClickListener(ViewHolder holder) {
this.rotate1 = holder.rlyCover;
this.rotate2 = holder.txvContent;
}
...
}
#16
问题解决了,是要用Hashmap把convertView装起来防其重用,谢谢各位了
#17
楼主 解决的能不能贴个代码啊 小白求教 也遇到这个问题了
#18
怎么解决的 贴代码啊
#19
问题解决了,是要用Hashmap把convertView装起来防其重用,谢谢各位了
楼主,具体怎么解决的啊??能详细点吗??
#20
事实证明这楼主得到自己想要的(或者找到解决办法) 就走了 只懂得获取需要的 不会给别人任何自己有的
#21
楼主贴代码~
#1
这个是convertView重用的结果,用map把控件旋转的状态保持起来,在getView里面根据这个状态设置控件。
#2
我也遇到过这种情况,我的listview上下拖动时原先响应的控件乱了,我认为应该是没记录响应控件的ID吧,我的解决方法是自定义了一个adapter,在里面写了一个数组记录每次响应控件的ID
#3
这个是convertView重用的结果,用map把控件旋转的状态保持起来,在getView里面根据这个状态设置控件。
麻烦您可不可以再详细点?
#4
自己顶下,寻求更多帮帮助
#5
你把代码贴下,估计是逻辑有问题
#6
你把代码贴下,估计是逻辑有问题
package com.sweetsopt.showeat.ui.adapter;
import java.util.HashMap;
import java.util.List;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.DecelerateInterpolator;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.dblife.frwe.anim.Rotate3dAnimation;
import com.dblife.frwe.utils.ImageUtils;
import com.dblife.frwe.utils.L;
import com.dblife.frwe.utils.PhoneUtils;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.sweetsopt.showeat.ui.ParamsHelper;
import com.sweetsopt.showeat.ui.bean.item.ShowtimeItemInfo;
import com.sweetspot.showeat.R;
/**
* <b>ClassName</b> FoodieShowPlusListAdatpter.java<br>
*
* <b>BuildTime:</b> 2015年1月4日<br>
* <b>Author:</b> Curzbin<br>
*
* <b>UpdateTime:</b> <br>
* <b>UpdateUser:</b> <br>
*
* <b>Description:</b> <br>
*/
public class FoodieShowPlusListAdatpter extends BaseAdapter{
private List<ShowtimeItemInfo> list;
private LayoutInflater mInflater;
private DisplayImageOptions options;
private HashMap<Integer, View> rlyMap = new HashMap<Integer, View>();
private HashMap<Integer, View> txvMap = new HashMap<Integer, View>();
public FoodieShowPlusListAdatpter(LayoutInflater mInflater, List<ShowtimeItemInfo> list) {
this.list = list;
this.mInflater = mInflater;
options = new DisplayImageOptions.Builder()
.showImageForEmptyUri(R.color.gray_level_2)
.showImageOnFail(R.color.gray_level_3)
.cacheInMemory(true)
.cacheOnDisk(true)
.resetViewBeforeLoading(true)
.considerExifParams(true)
.build();
}
@Override
public int getCount() {
return list.size();
}
@Override
public Object getItem(int position) {
return list.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.item_foodie_show_list_plus, parent, false);
holder = new ViewHolder();
holder.rlyCover = (RelativeLayout) convertView.findViewById(R.id.fsp_imgs);
holder.imgFsp = (ImageView) convertView.findViewById(R.id.fsp_cover);
holder.imgUserIcon = (ImageView) convertView.findViewById(R.id.fsp_usericon);
holder.txvContent = (TextView) convertView.findViewById(R.id.fsp_content);
holder.btnFavor = (ImageButton) convertView.findViewById(R.id.btn_favor);
holder.btnComment = (ImageButton) convertView.findViewById(R.id.btn_comment);
holder.btnCollect = (ImageButton) convertView.findViewById(R.id.btn_collection);
holder.btnShare = (ImageButton) convertView.findViewById(R.id.btn_share);
ImageUtils.setImageViewSize(holder.imgFsp, 4, 3);
ImageUtils.setImageViewSize(holder.txvContent, 4, 3);
rlyMap.put(position, holder.rlyCover);
txvMap.put(position, holder.txvContent);
convertView.setTag(holder);
holder.rlyCover.setOnClickListener(new OnRotateClickListener(position));
holder.txvContent.setOnClickListener(new OnRotateClickListener(position));
} else {
holder = (ViewHolder) convertView.getTag();
}
String urlContent = ParamsHelper.checkUrl(list.get(position).getPhoto());
String urlIcon = ParamsHelper.checkUrl(list.get(position).getUserphoto());
ImageLoader.getInstance().displayImage(urlIcon, holder.imgUserIcon, options);
ImageLoader.getInstance().displayImage(urlContent, holder.imgFsp, options);
holder.txvContent.setText(list.get(position).getContent());
return convertView;
}
public class OnRotateClickListener implements OnClickListener {
private View rotate1, rotate2;
float X = PhoneUtils.getScreenWidth() / 2;
float Y = PhoneUtils.getScreenHeight() / 2;
float Z = 20;
float localX = 0, localY = 0, localZ = -20;
int mDuration = 300, position;
public OnRotateClickListener(int position) {
this.rotate1 = rlyMap.get(position);
this.rotate2 = txvMap.get(position);
this.position = position;
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
L.i(position);
if (rotate1.getVisibility() == View.VISIBLE) {
applyRotation(rotate1, 1);
} else if (rotate2.getVisibility() == View.VISIBLE) {
applyRotation(rotate2, 2);
}
}
/**
*
* <b>Description:</b> <br>
*
* @param animView
*/
private void applyRotation(View animView, int page) {
Rotate3dAnimation rotation = new Rotate3dAnimation(0, 90, X, Y, Z, true);
rotation.setDuration(mDuration);
rotation.setFillAfter(true);
rotation.setCameraLocation(localX, localY, localZ);
rotation.setInterpolator(new AccelerateInterpolator());
rotation.setAnimationListener(new DisplayNextView(animView, page));
animView.startAnimation(rotation);
}
/**
* This class listens for the end of the first half of the animation. It
* then posts a new action that effectively swaps the views when the
* container is rotated 90 degrees and thus invisible.
*/
private final class DisplayNextView implements Animation.AnimationListener {
private int page;
public DisplayNextView(View view, int page) {
this.page = page;
}
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
if (page == 1) {
rotate1.setVisibility(View.INVISIBLE);
rotate2.setVisibility(View.VISIBLE);
rotate2.requestFocus();
Rotate3dAnimation rotation = new Rotate3dAnimation(-90, 0, X, Y, Z, false);
rotation.setDuration(mDuration);
rotation.setCameraLocation(localX, localY, localZ);
rotation.setFillAfter(true);
rotation.setInterpolator(new DecelerateInterpolator());
rotate2.startAnimation(rotation);
} else if (page == 2) {
rotate2.setVisibility(View.INVISIBLE);
rotate1.setVisibility(View.VISIBLE);
rotate1.requestFocus();
Rotate3dAnimation rotation = new Rotate3dAnimation(-90, 0, X, Y, Z, false);
rotation.setDuration(mDuration);
rotation.setCameraLocation(localX, localY, localZ);
rotation.setFillAfter(true);
rotation.setInterpolator(new DecelerateInterpolator());
rotate1.startAnimation(rotation);
}
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
}
}
/**
* Update data set
*
* @param list
*/
public void updateDataSet(List<ShowtimeItemInfo> list) {
this.list = list;
notifyDataSetChanged();
}
/**
* Add data set
*
* @param list
* a list of {@link ShowtimeItemInfo}
*/
public void addDataSet(List<ShowtimeItemInfo> list) {
this.list.addAll(list);
notifyDataSetChanged();
}
/**
* Add a data into list
*
* @param item
* object of {@link ShowtimeItemInfo}
*/
public void addOneData(ShowtimeItemInfo item) {
this.list.add(item);
notifyDataSetChanged();
}
/**
* update favorite number in ui
*
* @param favornum
* @param idx
*/
public void updateFavornum(String favornum, String idx) {
for (ShowtimeItemInfo item : list) {
if (item.getIdx().equals(idx)) {
item.setFavournum(favornum);
notifyDataSetChanged();
break;
}
}
}
private static class ViewHolder {
RelativeLayout rlyCover;
ImageView imgFsp, imgUserIcon;
TextView txvContent;
ImageButton btnFavor, btnShare, btnComment, btnCollect;
}
/**
* Show time buttons click listener
* @author FnsyBao
*
*/
public interface ShowTimeClickListener {
public void onFavorClick(String idx);
public void onCommentClick(String idx);
public void onShareClick();
public void onCollectionClick();
public void onFavorListClick(String idx);
}
/**
* To avoid overwrite too much function , <br>
* this adapter implements {@link ShowTimeClickListener}
* @author FnsyBao
*
*/
public class ShowTimeClickListenerAdapter implements ShowTimeClickListener {
@Override
public void onFavorClick(String idx) {}
@Override
public void onCommentClick(String idx) {}
@Override
public void onShareClick() {}
@Override
public void onCollectionClick() {}
@Override
public void onFavorListClick(String idx) {}
}
}
#7
holder.rlyCover.setOnClickListener(new OnRotateClickListener(position));
holder.txvContent.setOnClickListener(new OnRotateClickListener(position));这两句话 要写在逻辑外面
holder.txvContent.setOnClickListener(new OnRotateClickListener(position));这两句话 要写在逻辑外面
#8
holder.rlyCover.setOnClickListener(new OnRotateClickListener(position));
holder.txvContent.setOnClickListener(new OnRotateClickListener(position));这两句话 要写在逻辑外面
写在if...else...外面吗?没用啊
#9
应该有用啊,你写在里面是把每个控件都绑定了点击事件,你debug看看,每次点击的时候执行了什么
#10
rlyMap.put(position, holder.rlyCover);
txvMap.put(position, holder.txvContent);
这个的位置也有问题,而且你这样用也不太好啊。
直接在OnRotateClickListener构造的时候传递个holder就行了,干什么还要那么麻烦存到HashMap中。
#11
应该有用啊,你写在里面是把每个控件都绑定了点击事件,你debug看看,每次点击的时候执行了什么
debug的时候是跑了一遍onClick里面的内容,只有一遍,但是还是有别的item内容翻转了
#12
rlyMap.put(position, holder.rlyCover);
txvMap.put(position, holder.txvContent);
这个的位置也有问题,而且你这样用也不太好啊。
直接在OnRotateClickListener构造的时候传递个holder就行了,干什么还要那么麻烦存到HashMap中。
去了hashmap直接传holder也是一样的结果
#13
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.item_foodie_show_list_plus, parent, false);
holder = new ViewHolder();
holder.rlyCover = (RelativeLayout) convertView.findViewById(R.id.fsp_imgs);
holder.imgFsp = (ImageView) convertView.findViewById(R.id.fsp_cover);
holder.imgUserIcon = (ImageView) convertView.findViewById(R.id.fsp_usericon);
holder.txvContent = (TextView) convertView.findViewById(R.id.fsp_content);
holder.btnFavor = (ImageButton) convertView.findViewById(R.id.btn_favor);
holder.btnComment = (ImageButton) convertView.findViewById(R.id.btn_comment);
holder.btnCollect = (ImageButton) convertView.findViewById(R.id.btn_collection);
holder.btnShare = (ImageButton) convertView.findViewById(R.id.btn_share);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
ImageUtils.setImageViewSize(holder.imgFsp, 4, 3);
ImageUtils.setImageViewSize(holder.txvContent, 4, 3);
rlyMap.put(position, holder.rlyCover);
txvMap.put(position, holder.txvContent);
holder.rlyCover.setOnClickListener(new OnRotateClickListener(position));
holder.txvContent.setOnClickListener(new OnRotateClickListener(position));
String urlContent = ParamsHelper.checkUrl(list.get(position).getPhoto());
String urlIcon = ParamsHelper.checkUrl(list.get(position).getUserphoto());
ImageLoader.getInstance().displayImage(urlIcon, holder.imgUserIcon, options);
ImageLoader.getInstance().displayImage(urlContent, holder.imgFsp, options);
holder.txvContent.setText(list.get(position).getContent());
return convertView;
}
这样试试,如果还有问题,就等看看给OnRotateClickListener是不是有问题了
#14
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.item_foodie_show_list_plus, parent, false);
holder = new ViewHolder();
holder.rlyCover = (RelativeLayout) convertView.findViewById(R.id.fsp_imgs);
holder.imgFsp = (ImageView) convertView.findViewById(R.id.fsp_cover);
holder.imgUserIcon = (ImageView) convertView.findViewById(R.id.fsp_usericon);
holder.txvContent = (TextView) convertView.findViewById(R.id.fsp_content);
holder.btnFavor = (ImageButton) convertView.findViewById(R.id.btn_favor);
holder.btnComment = (ImageButton) convertView.findViewById(R.id.btn_comment);
holder.btnCollect = (ImageButton) convertView.findViewById(R.id.btn_collection);
holder.btnShare = (ImageButton) convertView.findViewById(R.id.btn_share);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
ImageUtils.setImageViewSize(holder.imgFsp, 4, 3);
ImageUtils.setImageViewSize(holder.txvContent, 4, 3);
rlyMap.put(position, holder.rlyCover);
txvMap.put(position, holder.txvContent);
holder.rlyCover.setOnClickListener(new OnRotateClickListener(position));
holder.txvContent.setOnClickListener(new OnRotateClickListener(position));
String urlContent = ParamsHelper.checkUrl(list.get(position).getPhoto());
String urlIcon = ParamsHelper.checkUrl(list.get(position).getUserphoto());
ImageLoader.getInstance().displayImage(urlIcon, holder.imgUserIcon, options);
ImageLoader.getInstance().displayImage(urlContent, holder.imgFsp, options);
holder.txvContent.setText(list.get(position).getContent());
return convertView;
}
这样试试,如果还有问题,就等看看给OnRotateClickListener是不是有问题了
一开始就是这样有问题我才把onClickListener拉到if里面试试的
#15
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.item_foodie_show_list_plus, parent, false);
holder = new ViewHolder();
holder.rlyCover = (RelativeLayout) convertView.findViewById(R.id.fsp_imgs);
holder.imgFsp = (ImageView) convertView.findViewById(R.id.fsp_cover);
holder.imgUserIcon = (ImageView) convertView.findViewById(R.id.fsp_usericon);
holder.txvContent = (TextView) convertView.findViewById(R.id.fsp_content);
holder.btnFavor = (ImageButton) convertView.findViewById(R.id.btn_favor);
holder.btnComment = (ImageButton) convertView.findViewById(R.id.btn_comment);
holder.btnCollect = (ImageButton) convertView.findViewById(R.id.btn_collection);
holder.btnShare = (ImageButton) convertView.findViewById(R.id.btn_share);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
ImageUtils.setImageViewSize(holder.imgFsp, 4, 3);
ImageUtils.setImageViewSize(holder.txvContent, 4, 3);
rlyMap.put(position, holder.rlyCover);
txvMap.put(position, holder.txvContent);
holder.rlyCover.setOnClickListener(new OnRotateClickListener(position));
holder.txvContent.setOnClickListener(new OnRotateClickListener(position));
String urlContent = ParamsHelper.checkUrl(list.get(position).getPhoto());
String urlIcon = ParamsHelper.checkUrl(list.get(position).getUserphoto());
ImageLoader.getInstance().displayImage(urlIcon, holder.imgUserIcon, options);
ImageLoader.getInstance().displayImage(urlContent, holder.imgFsp, options);
holder.txvContent.setText(list.get(position).getContent());
return convertView;
}
这样试试,如果还有问题,就等看看给OnRotateClickListener是不是有问题了
一开始就是这样有问题我才把onClickListener拉到if里面试试的
那就是OnRotateClickListener里面获取的控件有问题,直接传holder.
rlyMap.put(position, holder.rlyCover);
txvMap.put(position, holder.txvContent);
holder.rlyCover.setOnClickListener(new OnRotateClickListener(position));
holder.txvContent.setOnClickListener(new OnRotateClickListener(position));
改成
holder.rlyCover.setOnClickListener(new OnRotateClickListener(holder));
holder.txvContent.setOnClickListener(new OnRotateClickListener(holder));
holder也改下
public class OnRotateClickListener implements OnClickListener {
private View rotate1, rotate2;
...
public OnRotateClickListener(ViewHolder holder) {
this.rotate1 = holder.rlyCover;
this.rotate2 = holder.txvContent;
}
...
}
#16
问题解决了,是要用Hashmap把convertView装起来防其重用,谢谢各位了
#17
楼主 解决的能不能贴个代码啊 小白求教 也遇到这个问题了
#18
怎么解决的 贴代码啊
#19
问题解决了,是要用Hashmap把convertView装起来防其重用,谢谢各位了
楼主,具体怎么解决的啊??能详细点吗??
#20
事实证明这楼主得到自己想要的(或者找到解决办法) 就走了 只懂得获取需要的 不会给别人任何自己有的
#21
楼主贴代码~