原文  http://blog.csdn.net/dawanganban/article/details/21376979

前一段时间在做一个项目的时候遇到了一个关于BaseAdapter的notifyDataSetChanged()方法无效问题,当时在网上搜了一个解决方法,今天又遇到了一个类似的问题,我在这里做个记录,防止以后再次发生,或者其他朋友再次遇到。

一、ScrollView中嵌套ListView或GridView

原因:两个的滚动监听冲突

解决方法:重写ListView或GridView

package com.meritit.lottery.view;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ListView; public class SerialListView extends ListView { public SerialListView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
} public SerialListView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
} public SerialListView(Context context) {
super(context);
// TODO Auto-generated constructor stub
} /**
* 为了取消滚动效果,可以放入滚动组建中重写了此方法
*/
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> ,
MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expandSpec);
} }

二、ListView或GridView的外部容器重写onTouchEvent(MotionEvent event)方法

详细请看:http://blog.csdn.net/xxxzhi/article/details/12314775

这类问题解决方法很简单,只需要onTouchEvent返回false即可

例如:

@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
final int action = event.getAction();
final float x = event.getX();
final float y = event.getY(); switch (action) {
case MotionEvent.ACTION_DOWN:
System.out.println("父类点击onTouchEvent");
Log.i("", "onTouchEvent ACTION_DOWN");
if (mVelocityTracker == null) {
mVelocityTracker = VelocityTracker.obtain();
mVelocityTracker.addMovement(event);
}
if (!mScroller.isFinished()){
mScroller.abortAnimation();
}
mLastMotionX = x;
mLastMotionY = y;
break; case MotionEvent.ACTION_MOVE:
System.out.println("父类滑动onTouchEvent");
int deltaX = (int)(mLastMotionX - x);
if (IsCanMove(deltaX))
{
if (mVelocityTracker != null)
{
mVelocityTracker.addMovement(event);
}
mLastMotionX = x;
scrollBy(deltaX, );
} break;
case MotionEvent.ACTION_UP:
System.out.println("父类放开onTouchEvent");
int velocityX = ;
if (mVelocityTracker != null)
{
mVelocityTracker.addMovement(event);
mVelocityTracker.computeCurrentVelocity();
velocityX = (int) mVelocityTracker.getXVelocity();
}
if (velocityX > SNAP_VELOCITY && mCurScreen > ) {
// Fling enough to move left
Log.e(TAG, "snap left");
snapToScreen(mCurScreen - );
} else if (velocityX < -SNAP_VELOCITY
&& mCurScreen < getChildCount() - ) {
// Fling enough to move right
Log.e(TAG, "snap right");
snapToScreen(mCurScreen + );
} else {
snapToDestination();
} if (mVelocityTracker != null) {
mVelocityTracker.recycle();
mVelocityTracker = null;
}
// mTouchState = TOUCH_STATE_REST;
break;
}
return false;
}

三、数据传值问题

注意改变Adapter内的数据,如下:list_contents和toparr是改变后的数据

mycqbaseAdapter.contents=list_contents;
mycqtitleAdapter.toparr = toparr;
mycqbaseAdapter.notifyDataSetChanged();
mycqtitleAdapter.notifyDataSetChanged();

有一种错误的写法就是直接调用notifyData方法

mycqbaseAdapter.notifyDataSetChanged();
mycqtitleAdapter.notifyDataSetChanged();

BaseAdapter导致notifyDataSetChanged()无效的三个原因及处理方法的更多相关文章

  1. BaseAdapter导致notifyDataSetChanged()无效的四个原因及处理方法

    前一段时间在做一个项目的时候遇到了一个关于BaseAdapter的notifyDataSetChanged()方法无效问题,当时在网上搜了一个解决方法,今天又遇到了一个类似的问题,我在这里做个记录,防 ...

  2. (转)Putty server refused our key的三种原因和解决方法

    原文 上一篇博文介绍了使用Putty免密码登录,我后面试了另一台虚拟机,结果putty显示错误server refused our key(在linux下则表现为仍需要输入密码),搜索了下,很多人都遇 ...

  3. Android的setVisibility(View.GONE)无效的问题及原因分析(转)

    出现这种情况很可能是因为设置了animation,并且调用了setFillAfter(true),这就会导致setVisibility无效,只需要调用一下clearAnimation()方法或者去掉s ...

  4. Android的setVisibility(View.GONE)无效的问题及原因分析

    出现这种情况很可能是因为设置了animation,并且调用了setFillAfter(true),这就会导致setVisibility无效,只需要调用一下clearAnimation()方法或者去掉s ...

  5. Android setVisibility(View.GONE)无效的问题及原因分析

    解决方案:可以在setVisibility()之前调用clearAnimation()方法清除掉动画,或setFillAfter(false)(时间上该函数内部也调用了clearAnimation() ...

  6. Android 关于ListView中adapter调用notifyDataSetChanged无效的原因

    话说这个问题已经困扰我很久了,一直找不到原因,我以为只要数据变了,调用adapter的notifyDataSetChanged就会更新列表,最近在做微博帐号管理这一块,想着动态更新列表,数据是变了,但 ...

  7. Android开发之关于ListView中adapter调用notifyDataSetChanged无效的原因

    1.数据源没有更新,调用notifyDataSetChanged无效. 2.数据源更新了,但是它指向新的引用,调用notifyDataSetChanged无效. 3.数据源更新了,但是adpter没有 ...

  8. Android RecyclerView遇到notifyDataSetChanged无效时的解决方案

    一.简述 不管AbsListView(ListView.GridView)或是新出的RecyclerView,在使用notifyDataSetChanged方法更新列表数据时,一定要保证数据为同个对象 ...

  9. 终于懂了:FWinControls子控件的显示是由Windows来管理,而不是由Delphi来管理(显示透明会导致计算无效区域的方式有所不同——透明的话应减少剪裁区域,所以要进行仔细计算)

    在研究TCustomControl的显示过程中,怎么样都找不到刷新FWinControls并重新显示的代码: procedure TWinControl.PaintHandler(var Messag ...

随机推荐

  1. Windows Message Queue--hdu1509

    Windows Message Queue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Ot ...

  2. GO学习资源站

    GO语言学习资源网站 http://golangtc.com https://gobyexample.com http://golang-examples.tumblr.com

  3. linux下维护服务器之常用命令

    linux下维护服务器之常用命令! 第1套如下: 正则表达式: 1.如何不要文件中的空白行和注释语句: [root@localhost ~]# grep -v '^$' 文件名 |grep -v '^ ...

  4. Android常用代码

    1.图片旋转 Bitmap bitmapOrg = BitmapFactory.decodeResource(this.getContext().getResources(), R.drawable. ...

  5. [Leetcode][Python]54: Spiral Matrix

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 54: Spiral Matrixhttps://leetcode.com/p ...

  6. 【POJ 3009 Curling2.0 迷宫寻径 DFS】

    http://poj.org/problem?id=3009 模拟冰壶的移动,给出到达终点的最少投掷次数(不可达时为-1). 具体移动规则如下: 每次选四个方向之一,沿此方向一直前进,直到撞到bloc ...

  7. hdu 5616 Jam's balance(dp 正反01背包)

    来自官方题解: AC代码: #pragma comment(linker, "/STACK:1024000000,1024000000") #include<iostream ...

  8. OC基础16:复制对象

    "OC基础"这个分类的文章是我在自学Stephen G.Kochan的<Objective-C程序设计第6版>过程中的笔记. 1.浅复制即是指针赋值,复制对象的修改会影 ...

  9. MS SQL 当记录不存在时插入insert INTO not exists

    INSERT INTO dbo.[T_DabaoTemp]  ([PType]           ,[pID]           ,[NewVersion]           ,[ParentC ...

  10. 连接时出现:Can&#39;t open display: localhost:10.0

    解决方法: 在/etc/hosts 中增加 127.0.0.1 localhost ipaddress hostname 之后能进入图形界面,注意是实际ip和机器名 $(function () { $ ...