当前位置:   article > 正文

Android做分页加载的思路_android gridview分页显示

android gridview分页显示
package com.example.app5.ui.fragment;


import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.GridView;
import android.widget.SimpleAdapter;

import com.example.app5.R;
import com.example.app5.base.BaseFragment;
import com.example.app5.base.OkHttp;
import com.example.app5.data.MeetImge;
import com.example.app5.ui.adapter.ImageAdpter;

import org.jetbrains.annotations.NotNull;

import java.util.List;
import java.util.Map;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

public class NavigationFragment1 extends BaseFragment {

    private Context mContext;
    private List<Map<String, Object>> data_list;
    private SimpleAdapter sim_adapter;
    private GridView gview;
//    private int mPage;//全局变量要m开头
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        //注意View对象的重复使用,以便节省资源

        return inflater.inflate(R.layout.fragment_navigation1, container, false);

    }

    @Override
    public void onViewCreated(@NonNull @NotNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        gview = view.findViewById(R.id.gview);

//        gview.setOnScrollListener(new AbsListView.OnScrollListener() {
//            @Override
//            public void onScrollStateChanged(AbsListView absListView, int i) {
//                mPage = 1;
//                if (httpRes.isSuccessful()) {
//                    List<MeetImge> data = httpRes.dataFromList(MeetImge.class);
//                    adapter.addAll(data);
//                    mPage++;
//                }
//            }//设置下滑监听,mpage赋值为1,当什么的时候就++
//
//            @Override
//            public void onScroll(AbsListView absListView, int i, int i1, int i2) {
//                OkHttp.create().getIndexList(mPage).enqueue((call, httpRes) -> {
//                    Log.d("xxx", httpRes.toString());
//                    if (httpRes.isSuccessful()) {
//                        List<MeetImge> data = httpRes.dataFromList(MeetImge.class);
//                        adapter.addAll(data);
//                        mPage++;
//                    }
//                });
//            }
//        });
        ImageAdpter adapter = new ImageAdpter(getActivity());
        gview.setAdapter(adapter);

        OkHttp.create(this).getIndexList(1).enqueue((call, httpRes) -> {
            Log.d("xxx", httpRes.toString());
            if (httpRes.isSuccessful()) {
                List<MeetImge> data = httpRes.dataFromList(MeetImge.class);
                adapter.addAll(data);
//                mPage++;
            }
        });
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/286612
推荐阅读
相关标签
  

闽ICP备14008679号