• android ListView点击item返回后listview滚动位置


    1.Don't work when dynamically loading content 

    Parcelable state;
    
    @Override
    public void onPause() {    
        // Save ListView state @ onPause
        Log.d(TAG, "saving listview state @ onPause");
        state = listView.onSaveInstanceState();
        super.onPause();
    }
    ...
    
    @Override
    public void onViewCreated(final View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        // Set new items
        listView.setAdapter(adapter);
        ...
        // Restore previous state (including selected item index and scroll position)
        if(state != null) {
            Log.d(TAG, "trying to restore listview state..");
            listView.onRestoreInstanceState(state);
        }
    }

     2.在listview点击事件中保存位置信息

    static int index ,top;
    listview.setOnItemClickListener(new OnItemClickListener() { @SuppressLint("ResourceAsColor") @Override public void onItemClick(final AdapterView<?> parent, View view, final int position, long id) { index = listview.getFirstVisiblePosition(); View v = listview.getChildAt(0); top = (v == null) ? 0 : (v.getTop() - listview.getPaddingTop()); } });
    listview.setAdapter(adapter);
    // restore index and position
    listview.setSelectionFromTop(index, top);
  • 相关阅读:
    vue中watch的详细用法
    Golang实现请求限流的几种办法
    观察者模式
    原创-阿里云上SLB暴露K8S服务-四层协议/七层协议
    K8S-HPA创建指南
    阿里云k8s-nas挂载指南
    非原创--mysql语言分类
    mysql命令
    MongoDB从节点支持读请求
    MongoDB用户权限管理
  • 原文地址:https://www.cnblogs.com/andies/p/5833506.html
Copyright © 2020-2023  润新知