Closed douya40 closed 8 years ago
我马上解决下!
请贴一下你的布局文件吧!
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/transparent" android:orientation="vertical">
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
>
<com.github.jdsjlzx.recyclerview.LuRecyclerView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</android.support.v4.widget.SwipeRefreshLayout>
是设置item点击事件报错吗?贴一下出错log!
Process: com.laima365.laimaboss, PID: 31060 java.lang.NullPointerException: Attempt to invoke virtual method 'void com.github.jdsjlzx.recyclerview.LuRecyclerViewAdapter.setScrollState(int)' on a null object reference at com.github.jdsjlzx.recyclerview.LuRecyclerView.onScrollStateChanged(LuRecyclerView.java:276) at android.support.v7.widget.RecyclerView.dispatchOnScrollStateChanged(RecyclerView.java:4334) at android.support.v7.widget.RecyclerView.setScrollState(RecyclerView.java:1290) at android.support.v7.widget.RecyclerView$ViewFlinger.fling(RecyclerView.java:4517) at android.support.v7.widget.RecyclerView.fling(RecyclerView.java:1945) at android.support.v7.widget.RecyclerView.onTouchEvent(RecyclerView.java:2725) at android.view.View.dispatchTouchEvent(View.java:9427) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2660) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2304) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2666) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2318) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2666
引用 compile 'com.github.jdsjlzx:LRecyclerView:1.2.1' 试试,如还有问题请提出详细log。
感谢你对本框架的支持和理解,有问题及时提出,我会尽快解决…
compile 'com.github.jdsjlzx:LRecyclerView:1.2.1' 多次点击还有问题 java.lang.NullPointerException: Attempt to invoke virtual method 'void com.github.jdsjlzx.recyclerview.LuRecyclerViewAdapter.setScrollState(int)' on a null object reference at com.github.jdsjlzx.recyclerview.LuRecyclerView.onScrollStateChanged(LuRecyclerView.java:276) at android.support.v7.widget.RecyclerView.dispatchOnScrollStateChanged(RecyclerView.java:4334) at android.support.v7.widget.RecyclerView.setScrollState(RecyclerView.java:1290) at android.support.v7.widget.RecyclerView$ViewFlinger.fling(RecyclerView.java:4517) at android.support.v7.widget.RecyclerView.fling(RecyclerView.java:1945) at android.support.v7.widget.RecyclerView.onTouchEvent(RecyclerView.java:2725) at android.view.View.dispatchTouchEvent(View.java:9427) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2660) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2304) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2666) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2318) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2666) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2318) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2666) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2318) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2666)
多次点击这个你代码是怎么写的,贴出来看看
import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.content.ContextCompat; import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.widget.LinearLayoutManager; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.github.jdsjlzx.recyclerview.LuRecyclerView; import com.github.jdsjlzx.recyclerview.LuRecyclerViewAdapter; import com.github.jdsjlzx.util.LuRecyclerViewStateUtils; import com.github.jdsjlzx.view.LoadingFooter; import com.laima365.laimaboss.R; import com.laima365.laimaboss.event.StartBrotherEvent; import com.laima365.laimaboss.model.BaseModel; import com.laima365.laimaboss.model.IntegralUserList; import com.laima365.laimaboss.model.JBModel; import com.laima365.laimaboss.model.RechargeUserList; import com.laima365.laimaboss.nohttp.CallServer; import com.laima365.laimaboss.nohttp.FastJsonRequest; import com.laima365.laimaboss.nohttp.HttpListener; import com.laima365.laimaboss.ui.activity.BaseAppCompatActivity; import com.laima365.laimaboss.ui.adapter.RecycleHolder; import com.laima365.laimaboss.ui.adapter.RecyclerAdapter; import com.laima365.laimaboss.ui.view.RecycleViewDivider; import com.laima365.laimaboss.utils.AppUtil; import com.laima365.laimaboss.utils.Constants; import com.laima365.laimaboss.utils.GlideImgManager; import com.laima365.laimaboss.utils.ToastUtils; import com.yolanda.nohttp.RequestMethod; import com.yolanda.nohttp.rest.Request; import com.yolanda.nohttp.rest.Response;
import org.greenrobot.eventbus.EventBus;
import java.util.ArrayList; import java.util.List;
import butterknife.BindView; import butterknife.ButterKnife;
/**
_/
public class JfFragment extends BaseFragment implements HttpListener
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.jffragment, container, false);
ButterKnife.bind(this, view);
return view;
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
initData();
initEvent();
addUserShopRemark();
}
private void initData() {
//设置刷新时动画的颜色,可以设置4个
if (mSwipeRefreshLayout != null) {
mSwipeRefreshLayout.setProgressViewOffset(false, 0, AppUtil.dip2px(getActivity(),48));
mSwipeRefreshLayout.setColorSchemeResources(android.R.color.holo_blue_light, android.R.color.holo_red_light, android.R.color.holo_orange_light, android.R.color.holo_green_light);
mSwipeRefreshLayout.setOnRefreshListener(this);
}
mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
mRecyclerView.addItemDecoration(new RecycleViewDivider(
getActivity(), LinearLayoutManager.HORIZONTAL, 2, ContextCompat.getColor(getActivity(), R.color.line)));
mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
mRecyclerView.addItemDecoration(new RecycleViewDivider(
getActivity(), LinearLayoutManager.HORIZONTAL, 2, ContextCompat.getColor(getActivity(), R.color.line)));
}
private void initEvent() {
mRecyclerView.setLScrollListener(new LuRecyclerView.LScrollListener() {
@Override
public void onScrollUp() {
}
@Override
public void onScrollDown() {
}
@Override
public void onBottom() {
flag=MORE;
LoadingFooter.State state = LuRecyclerViewStateUtils.getFooterViewState(mRecyclerView);
if(state == LoadingFooter.State.Loading) {
return;
}
// if (pageNum < TOTAL_COUNTER) { pageNum++; LuRecyclerViewStateUtils.setFooterViewState(getActivity(), mRecyclerView, REQUEST_COUNT, LoadingFooter.State.Loading, null); addUserShopRemark(); // } else { //the end // LuRecyclerViewStateUtils.setFooterViewState(getActivity(), mRecyclerView, REQUEST_COUNT, LoadingFooter.State.TheEnd, null); // } } @Override public void onScrolled(int distanceX, int distanceY) { }
@Override
public void onScrollStateChanged(int state) {
}
});
}
/**
* 商家对用户印象标签
*/
private void addUserShopRemark() {
Request<JSONObject> request = new FastJsonRequest(Constants.API.INTEGRALUSERLIST_SHOPMANAGER, RequestMethod.POST);
request.add("pageNum",pageNum);
CallServer.getRequestInstance().add((BaseAppCompatActivity) getActivity(), INTEGRALUSERLIST, request, this, false, false);
}
private void showList(List<IntegralUserList.DataBean.UserShopScoreListBean> tlist) {
if (recyclerAdapter == null) {
jflist=tlist;
recyclerAdapter = new RecyclerAdapter<IntegralUserList.DataBean.UserShopScoreListBean>(getActivity(),jflist, R.layout.jf_item) {
@Override
public void convert(RecycleHolder holder,final IntegralUserList.DataBean.UserShopScoreListBean data, int position) {
GlideImgManager.loadImage(getActivity(),data.getIcon(),(ImageView) holder.findView(R.id.image_dpyg));
holder.setText(R.id.name,data.getName());
holder.setText(R.id.num,data.getScore());
holder.findView(R.id.relay_jf).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EventBus.getDefault().post(new StartBrotherEvent(SjDetailFragment.newInstance(data.getUserId()+"",2)));//2:积分
}
});
}
};
mLRecyclerViewAdapter = new LuRecyclerViewAdapter(recyclerAdapter);
mRecyclerView.setAdapter(mLRecyclerViewAdapter);
}else{
if (jflist == null || jflist.size() == 0) {
jflist = tlist;
} else {
for (int i = 0; i < tlist.size(); i++) {
jflist.add(tlist.get(i));
}
}
recyclerAdapter.onDateChange(jflist);
}
}
@Override
public void onSucceed(int what, Response<JSONObject> response) {
if(what==INTEGRALUSERLIST){
BaseModel info = JSON.parseObject(response.get().toString(), BaseModel.class);
if (info.getState() == Constants.SUCCEED) {
IntegralUserList reinfo = JSON.parseObject(response.get().toString(), IntegralUserList.class);
if(flag==REFRESH){
mSwipeRefreshLayout.setRefreshing(false);
}else{
LuRecyclerViewStateUtils.setFooterViewState(mRecyclerView, LoadingFooter.State.Normal);
mSwipeRefreshLayout.setRefreshing(false);
}
if(reinfo.getData().getUserShopScoreList().size()==0){
ToastUtils.show("数据加载完!");
LuRecyclerViewStateUtils.setFooterViewState(getActivity(), mRecyclerView, REQUEST_COUNT, LoadingFooter.State.TheEnd, null);
}else{
showList(reinfo.getData().getUserShopScoreList());
}
} else {
JBModel jbinfo = JSON.parseObject(response.get().toString(), JBModel.class);
ToastUtils.show(jbinfo.getData());
}
}
}
@Override
public void onFailed(int what, Response<JSONObject> response) {
((BaseAppCompatActivity) getActivity()).showMessageDialog(R.string.request_failed, response.getException().getMessage());
}
@Override
public void onRefresh() {
flag=REFRESH;
pageNum =1;
mSwipeRefreshLayout.setRefreshing(true);
addUserShopRemark();
}
}
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/transparent" android:orientation="vertical"> <android.support.v4.widget.SwipeRefreshLayout android:id="@+id/swipe_refresh_jflayout" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior"
<com.github.jdsjlzx.recyclerview.LuRecyclerView
android:id="@+id/jf_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</android.support.v4.widget.SwipeRefreshLayout>
你加我QQ:573842281,我远程给你看看吧!
compile 'com.github.jdsjlzx:LRecyclerView:1.2.2' 新版本解决问题!
LuRecyclerView 数据为空点击奔溃