我有一个非常奇怪的错误,我无法理解。以下是视频格式http://www.youtube.com/watch?v=hHuUzNDI68w
中的行为现在解释一下。我有一个名为NewsFeed的活动。它包含一个FeedView的ListView(每个都有一个来自url的照片,我使用缓存类加载,旁边有一些文本)如果我打开这个活动,一切都没问题,当我滚动所有内容时按预期工作。但是,如果我首先按下搜索键,其中键盘出现,并且我从搜索结果中选择了某些内容,则会打开NewsFeed活动 首先当它出现时,键盘仍然是向上,然后一瞬间键盘向下,最终结果是顶部的2个图像是相同的(它们不应该是)
通过一些调试我发现由于某种原因,前2行的viewHolder最终成为第二轮的同一个对象(一旦键盘终于消失了)
public View getView (int position, View convertView, ViewGroup parent) {
final HashMap<String, Object> game = getItem(position);
CollapsedNewsHolder collapsedNewsHolder;
if (convertView == null) {
convertView = inflater.inflate(R.layout.news_collapsed_module, null);
collapsedNewsHolder = new CollapsedNewsHolder();
collapsedNewsHolder.newsPicture = (ImageView) convertView.findViewById(R.id.NewsPicture);
collapsedNewsHolder.progress = (ProgressBar) convertView.findViewById(R.id.Progress);
collapsedNewsHolder.title = (TextView) convertView.findViewById(R.id.title);
collapsedNewsHolder.newsPerson = (TextView) convertView.findViewById(R.id.newsPerson);
collapsedNewsHolder.upCount = (TextView) convertView.findViewById(R.id.upCount);
collapsedNewsHolder.commentCount = (TextView) convertView.findViewById(R.id.commentCount);
collapsedNewsHolder.relativeTime = (TextView) convertView.findViewById(R.id.RelativeTime);
collapsedNewsHolder.setTypeface();
//collapsedNewsHolder.imageCallback = new MyImageCallback(mActivity, collapsedNewsHolder.newsPicture, collapsedNewsHolder.progress, MyImageCallback.SMALL, 200);
//collapsedNewsHolder.itemClickListener = new ItemClickListener();
convertView.setTag(collapsedNewsHolder);
} else
collapsedNewsHolder = (CollapsedNewsHolder) convertView.getTag();
if ((Integer) getItem(position).get("type") != NewsFeed.POSTER)
collapsedNewsHolder.title.setTextSize(13f);
collapsedNewsHolder.newsPicture.setImageBitmap(null);
collapsedNewsHolder.progress.setVisibility(View.VISIBLE);
ImageUtil.imageCache.loadAsync((String) game.get("img"), new MyImageCallback(mActivity, collapsedNewsHolder.newsPicture, collapsedNewsHolder.progress, MyImageCallback.SMALL, 200), mContext);
collapsedNewsHolder.title.setText((String) game.get("title"));
collapsedNewsHolder.newsPerson.setText((String)game.get("newsPerson"));
collapsedNewsHolder.relativeTime.setText((String) game.get("relativeTime"));
collapsedNewsHolder.upCount.setText((Integer) game.get("upCount") + "");
collapsedNewsHolder.commentCount.setText((Integer) game.get("commentCount") + "");
//convertView.setOnClickListener(collapsedNewsHolder.itemClickListener.set((String) game.get("id"), position));
convertView.setOnClickListener(new ItemClickListener((String) game.get("id"), position));
return convertView;
}
此处还有一个说明问题的错误日志。请注意关于列表中位置的内存位置和图像URL。
05-05 17:34:54.774: ERROR/NewsFeedAdapter(7101): Position- 0 Image- android.widget.ImageView@460977f8 Loading image- http://lh3.ggpht.com/o0vA6-MRGAXhhYYkPa1xf3WsPlDe4XnK2xWZeMhmXKBQI8eHGTAos0l1zqC_nox2MrRHKcCKNnPgzqLctsqh25e3LMc=s500
05-05 17:34:54.804: ERROR/NewsFeedAdapter(7101): Position- 1 Image- android.widget.ImageView@46142f28 Loading image- http://lh6.ggpht.com/RcTe-3O-Rywdp0zizVx6k6lSEuPpYbDYnu1UoEnWbhLk6BzwzXt29BvK5rMPAqkrhgtvxvddSTL3pBnMDeLIXVV3s0EZng=s500
05-05 17:34:55.154: ERROR/NewsFeedAdapter(7101): Position- 0 Image- android.widget.ImageView@46142f28 Loading image- http://lh3.ggpht.com/o0vA6-MRGAXhhYYkPa1xf3WsPlDe4XnK2xWZeMhmXKBQI8eHGTAos0l1zqC_nox2MrRHKcCKNnPgzqLctsqh25e3LMc=s500
05-05 17:34:55.174: ERROR/NewsFeedAdapter(7101): Position- 1 Image- android.widget.ImageView@460977f8 Loading image- http://lh6.ggpht.com/RcTe-3O-Rywdp0zizVx6k6lSEuPpYbDYnu1UoEnWbhLk6BzwzXt29BvK5rMPAqkrhgtvxvddSTL3pBnMDeLIXVV3s0EZng=s500
05-05 17:34:55.304: ERROR/NewsFeedAdapter(7101): Position- 2 Image- android.widget.ImageView@4615cd28 Loading image- http://lh4.ggpht.com/V95vJI4WHUUluC8_jHaJw011U6RO7I9rVBQsdSvwDrnUrOCN2YvqhHftr7o0YMNv8cIEBEjsnLNvIH0Y1KoB-rzw6hrKiQ=s500
05-05 17:34:55.334: ERROR/NewsFeedAdapter(7101): Position- 3 Image- android.widget.ImageView@46061610 Loading image- http://lh3.ggpht.com/-c7Ss0t2luOD-npAFZcjRYbnuasqjUNTOv75pFhyprhyzGDf8QdIz_PrJS5qcmBb0a5xrXzZWZYH7oc06eo=s500
05-05 17:34:55.384: ERROR/NewsFeedAdapter(7101): Position- 4 Image- android.widget.ImageView@4613d058 Loading image- http://lh3.ggpht.com/iCKp7kwcnbnZGD4vBb-Mz_mtSKPvST-YGeekJ9khljpG-Ua5Kl71ETdn8LLulULmq9fgNy8huooi_CfrT4W3gjqoFhiB=s500
答案 0 :(得分:1)
我有类似的问题。我通过将android:windowSoftInputMode
设置为adjustPan
来解决此问题。