2 captian jhl Captian_JHL 于 2016.03.16 17:03 提问

SwipeRefreshLayout中嵌套ListView数据不主动显示 2C

我在SwipeRefreshLayout中嵌套了ListView,在启动应用的时候,通过网络加载数据到ListView显示,出现了问题。每次运行APP进入主界面的时候,数据可以加载成功,但是ListView显示时必须要点击一下手机屏幕,才会把数据显示出来,请问这是什么原因造成的?

11个回答

zrf1335348191
zrf1335348191   2016.03.16 17:27

贴上这部分代码看看,是说点击屏幕还是说上拉或下拉刷新时显示数据?

Captian_JHL
Captian_JHL   2016.03.16 17:35

我意思是:我的数据可以加载,也可以显示,但是有一个Bug,就是打开APP,进入主界面的时候,我要点击一下屏幕,ListView的数据才会显示出来。

Captian_JHL
Captian_JHL   2016.03.16 17:38

图片说明
图片说明
就是我进到这个主界面数据不显示,我点击一下数据就显示了

Captian_JHL
Captian_JHL   2016.03.16 17:39

NoticeInfoFragment.java
package njit.com.stuinfosys.activities;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.widget.SwipeRefreshLayout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.Toast;

import njit.com.stuinfosys.R;
import njit.com.stuinfosys.adapter.NoticeAdapter;
import njit.com.stuinfosys.tools.ResolveNoticeData;
import njit.com.stuinfosys.tools.SystemInfo;

/**

  • Created by Captain_JHL on 2016/3/7 0007.
    */
    public class NoticeInfoFragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener {

    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";
    private String mParam1;
    private String mParam2;

    public static final int REFRESH_SUCCESS = 1;
    public static final int REFRESH_FAILURE = 2;

    private ListView mNoticeListView;
    private NoticeAdapter mNoticeAdapter;
    private SwipeRefreshLayout mSwipeRefreshLayout;
    private ResolveNoticeData mResolveNoticeData;

    public NoticeInfoFragment() {
    // default construct
    mResolveNoticeData = new ResolveNoticeData();
    }

    public static NoticeInfoFragment newInstance(String param1, String param2) {
    Bundle args = new Bundle();
    NoticeInfoFragment fragment = new NoticeInfoFragment();
    args.putString(ARG_PARAM1, param1);
    args.putString(ARG_PARAM2, param2);
    fragment.setArguments(args);
    return fragment;
    }

    private Handler mHandler = new Handler() {
    @Override
    public void handleMessage(Message msg) {
    if (msg.what == REFRESH_SUCCESS) {
    Toast.makeText(getActivity().getApplicationContext(), "刷新成功", Toast.LENGTH_SHORT).show();
    mSwipeRefreshLayout.setRefreshing(false);
    } else if (msg.what == REFRESH_FAILURE) {
    Toast.makeText(getActivity().getApplicationContext(), "刷新失败", Toast.LENGTH_SHORT).show();
    mSwipeRefreshLayout.setRefreshing(false);
    }
    }
    };

    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (getArguments() != null) {
    mParam1 = getArguments().getString(ARG_PARAM1);
    mParam2 = getArguments().getString(ARG_PARAM2);
    }
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    return inflater.inflate(R.layout.fragment_notice_info, container, false);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    mNoticeListView = (ListView) getView().findViewById(R.id.lv_notice_info);
    mSwipeRefreshLayout = (SwipeRefreshLayout) getView().findViewById(R.id.swipe_refresh);
    mNoticeAdapter = new NoticeAdapter(getActivity().getApplicationContext());
    mNoticeListView.setAdapter(mNoticeAdapter);
    mSwipeRefreshLayout.setOnRefreshListener(this);
    }

    @Override
    public void onRefresh() {
    if (SystemInfo.isNetWorkAvailable(getActivity().getApplicationContext())) {
    new Thread(new Runnable() {
    @Override
    public void run() {
    boolean result = mResolveNoticeData.getHtmlData();
    if (result) {
    mHandler.sendEmptyMessage(REFRESH_SUCCESS);
    } else {
    mHandler.sendEmptyMessage(REFRESH_FAILURE);
    }
    }
    }).start();
    } else {
    mHandler.sendEmptyMessage(REFRESH_FAILURE);
    }
    }

    @Override
    public void onDestroy() {
    super.onDestroy();
    mResolveNoticeData.cacheToDatabase(getActivity().getApplicationContext());
    }
    }

Captian_JHL
Captian_JHL   2016.03.16 17:42

Captian_JHL
Captian_JHL   2016.03.16 17:43

Captian_JHL
Captian_JHL   2016.03.16 17:43

不太会插入代码片,不知道怎么传,传了2次空白

Captian_JHL
Captian_JHL   2016.03.16 17:44

Captian_JHL
Captian_JHL   2016.03.16 17:44
lxk_1993
lxk_1993   Rxr 2016.03.16 18:01

应该是SwipeRefreshLayout的bug 你可以换个下拉刷新的控件 https://github.com/android-cjj/BeautifulRefreshLayout 这里有20多种刷新加载

共11条数据 1 尾页
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!