@Override
protected void onPostExecute(Void result) {
newTestLv = (ListView) getActivity().findViewById(R.id.test_huiyuan_lv);
TextView noNetwork = (TextView) getActivity().findViewById(R.id.test_huiyuan_empty_tv);
newTestLv.setEmptyView(noNetwork);
mAdapter = new TestSingleAdapter(getActivity(),newTestList);
newTestLv.setAdapter(mAdapter);
mAdapter.notifyDataSetChanged();
//注册上下文菜单
//registerForContextMenu(newProblemLv);
if (newTestList != null && !newTestList.isEmpty()) {
noNetwork.setVisibility(View.GONE);
} else {
noNetwork.setVisibility(View.VISIBLE);
}
newTestLv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> listView, View itemView, int index, long id) {
Test test = newTestList.get(index);
Bundle bundle = new Bundle();
bundle.putSerializable("TEST", test);
UiHelper.showFragment(FragmentHuiyuan.this, bundle, new TestDetailFragment());
}
});
newTestLv.setOnScrollListener(new OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) { }
@Override
public void onScroll(AbsListView listView, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
int lastItemIndex = listView.getLastVisiblePosition();//当前屏幕最后一条记录ID
if(lastItemIndex + 1 == totalItemCount && isLoadFinish){//判断往下是否达到数据最后一条记录
//锁定加载完成标志
isLoadFinish = false;
//根据页码获取最新数据
try {
addDataAtBackground();
} catch (Exception e) {
e.printStackTrace();
}
}
}
});
if(NetWorkHelper.isNetworkConnected(mApp)){
addDataAtBackground();
}else{
noNetwork.setText("网络未连接,请检查移动数据是否打开或点击标题栏刷新");
noNetwork.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mApp.postEvent(new OnReceivedRefreshNewsShownEvent(NoticeType.NOTIFICATION));
}
});
}
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return UiHelper.getLightThemeView(getActivity(), R.layout.fragment_test_huiyuan);
}
@Override
public void onViewCreated(View v, Bundle savedInstanceState) {
super.onViewCreated(v, savedInstanceState);
//TextView title = (TextView) v.findViewById(R.id.title_text);
//title.setText("会员测试");
new RemoteDataTask().execute();
}
布局文件:
<?xml version="1.0" encoding="utf-8"?>
android:layout_width="match_parent"
android:layout_height="match_parent" >
android:id="@+id/the_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<ListView
android:id="@+id/test_huiyuan_lv"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:listSelector="#00000000"
android:cacheColorHint="#00000000"
android:divider="@color/xian_yanse"
android:dividerHeight="1px"
android:scrollbars="@null"
android:layout_below="@+id/the_title"
/>
<TextView
android:id="@+id/test_huiyuan_empty_tv"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center"
android:textColor="@color/blue"
android:text="@string/isNetwork"
android:padding="20dp"
android:visibility="gone" />
有没有朋友遇到相同的问题,我已经在这里卡住了两天了