在recyclerview Scroll上强制关闭应用程序

时间:2016-08-18 15:30:54

标签: java android scroll android-recyclerview forceclose

当我在我的应用程序中滚动Recyclerview时,它会关闭。

以下是截图:

应用程序的主页 - 当我滚动主页的reyclerview我的应用程序强行关闭时:

!

这是我的适配器:

public class RecyclerViewDataAdapter extends RecyclerView.Adapter<RecyclerViewDataAdapter.ItemRowHolder> {

private ArrayList<SectionDataModel> dataList;
private Context mContext;
private ImageView bg;
private boolean isLang;



public RecyclerViewDataAdapter(Context context, ArrayList<SectionDataModel> dataList) {
    this.dataList = dataList;
    this.mContext = context;
}

@Override
public ItemRowHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
    View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.list_item, null);
    ItemRowHolder mh = new ItemRowHolder(v);
    return mh;
}

@Override
public void onBindViewHolder(final ItemRowHolder itemRowHolder, int i) {

    final String sectionName = dataList.get(i).getHeaderTitle();
    final String sectionSub = dataList.get(i).getHeaderSubTitle();
    final int sectionhesder = dataList.get(i).getHeader();

    final int bgd = dataList.get(i).getPhoto();
    final int bgg = dataList.get(i).getBg();
    ArrayList singleSectionItems = dataList.get(i).getAllItemsInSection();

    itemRowHolder.itemSubTitle.setText(sectionSub);
    itemRowHolder.itemTitle.setText(sectionName);
    itemRowHolder.bg.setImageResource(bgd);

    itemRowHolder.bg.setBackgroundResource(bgg);
    if (isLang = Locale.getDefault().getLanguage().equals("fa")) {
        itemRowHolder.bg.setScaleType(ImageView.ScaleType.FIT_START);

    } else {
        itemRowHolder.bg.setScaleType(ImageView.ScaleType.FIT_END);
    }


    SectionListDataAdapter itemListDataAdapter = new SectionListDataAdapter(mContext, singleSectionItems);

    itemRowHolder.recycler_view_list.setHasFixedSize(true);
    itemRowHolder.recycler_view_list.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.HORIZONTAL, false));
    itemRowHolder.recycler_view_list.setAdapter(itemListDataAdapter);

    itemRowHolder.recycler_view_list.setNestedScrollingEnabled(false);


   /*  itemRowHolder.recycler_view_list.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            int action = event.getAction();
            switch (action) {
                case MotionEvent.ACTION_DOWN:
                    // Disallow ScrollView to intercept touch events.
                    v.getParent().requestDisallowInterceptTouchEvent(true);
                    break;
                case MotionEvent.ACTION_UP:
                    //Allow ScrollView to intercept touch events once again.
                    v.getParent().requestDisallowInterceptTouchEvent(false);
                    break;
            }
            // Handle RecyclerView touch events.
            v.onTouchEvent(event);
            return true;
        }
    });*/

    itemRowHolder.btnMore.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(mContext, TopicActivity.class);
            intent.putExtra("topicn",sectionName.toString());
            intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
            mContext.startActivity(intent);




        }
    });




   /* Glide.with(mContext)
            .load(feedItem.getImageURL())
            .diskCacheStrategy(DiskCacheStrategy.ALL)
            .centerCrop()
            .error(R.drawable.bg)
            .into(feedListRowHolder.thumbView);*/
}

@Override
public int getItemCount() {
    return (null != dataList ? dataList.size() : 0);
}

public class ItemRowHolder extends RecyclerView.ViewHolder {


    protected RelativeLayout itemHeader;
    protected TextView itemTitle;
    protected TextView itemSubTitle;
    protected RecyclerView recycler_view_list;

    protected Button btnMore;

    public ImageView bg;


    public ItemRowHolder(View view) {
        super(view);

        this.itemTitle = (TextView) view.findViewById(R.id.itemTitle);
        this.itemSubTitle = (TextView) view.findViewById(R.id.itemsub);
        this.itemHeader = (RelativeLayout) view.findViewById(R.id.header);
        this.recycler_view_list = (RecyclerView) view.findViewById(R.id.recycler_view_list);
        this.btnMore= (Button) view.findViewById(R.id.btnMore);


        this.bg= (ImageView) view.findViewById(R.id.bg);
  }}}

0 个答案:

没有答案