赞
踩
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++; } }); } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。