Captian_JHL
neo_1949
采纳率0%
2016-03-16 09:03

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

2

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

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

9条回答

  • qq_30878303 wardenlzr 5年前

    在ListView 的XML里 加一个属性 android:transcriptMode="normal"

    点赞 评论 复制链接分享
  • lxk_1993 103style 5年前

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

    点赞 评论 复制链接分享
  • Captian_JHL neo_1949 5年前
    点赞 评论 复制链接分享
  • Captian_JHL neo_1949 5年前

    点赞 评论 复制链接分享
  • Captian_JHL neo_1949 5年前

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

    点赞 评论 复制链接分享
  • Captian_JHL neo_1949 5年前

    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 neo_1949 5年前

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

    点赞 评论 复制链接分享
  • Captian_JHL neo_1949 5年前

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

    点赞 评论 复制链接分享
  • zrf1335348191 fanfan-公众号-码农修仙儿 5年前

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

    点赞 评论 复制链接分享

相关推荐