ListView在滚动时阻止刷新

时间:2015-05-15 18:41:01

标签: android listview android-listview

在firebase聊天示例应用程序中,当数据更新(更改,删除,移动,添加)listview滚动到关闭时。 资料来源:https://github.com/firebase/AndroidChat

如何在上次scrollStateChanged后的30秒内阻止滚动?

        msgListView.setOnScrollListener(new AbsListView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
            scroll_idle_time = System.currentTimeMillis();
        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {

        }
    });

    public static boolean canScroll() {
    return scroll_idle_time + 30000 < System.currentTimeMillis();
}

3 个答案:

答案 0 :(得分:2)

将此代码放在getView函数的第一行:

/modelA/{id}/modelB/rel/{fk} 

答案 1 :(得分:1)

我用以下代码解决了

 public class CustomAdapter extends BaseAdapter {

    Activity activity;
    ArrayList<SectionsDetailsPOJO> alSectionDetails;

    public CustomAdapter(Activity a, ArrayList<SectionsDetailsPOJO> d) {
        activity = a;
        alSectionDetails = d;
    }


    @Override
    public int getViewTypeCount() {
        if(alSectionDetails.size()>0) {
            return alSectionDetails.size();
        }
        return 1;
    }

    @Override
    public int getItemViewType(int position) {
        return position;
    }

    @Override
    public int getCount() {
        if (alSectionDetails.size() <= 0)
            return 1;
        return alSectionDetails.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder;

        final LayoutInflater inflater = ( LayoutInflater )activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.custom_view, null);

            holder = new ViewHolder();
            holder.SectionNo = (TextView) convertView.findViewById(R.id.textView1);
            holder.SectionHeader=(TextView)convertView.findViewById(R.id.textView2);

            holder.SectionNo.setText(alSectionDetails.get(position).getSection_no());
            holder.SectionHeader.setText(alSectionDetails.get(position).getSection_header());

            convertView.setTag(holder);
        }
        else {
            holder = (ViewHolder) convertView.getTag();
            convertView.setTag(holder);
        }
        return convertView;
    }

    public  class ViewHolder {
        public TextView SectionNo;
        public TextView SectionHeader;
    }
}

答案 2 :(得分:0)

Retaining position in ListView after calling notifyDataSetChanged

找到解决方案
sprite = new Sprite (imgb); //work flawlessly

sprite2 = new Sprite ();
sprite2.setTexture (imgb); //doesn't do anything