Android |在RecyclerView上强制onClick方法

时间:2017-05-16 09:45:13

标签: android android-recyclerview

在我的应用程序中,我有动态垂直繁荣菜单。但是,只有当用户点击热门菜单按钮并且我想在活动创建后立即显示菜单时才打开菜单。我在这个问题上搜索了解决方案,发现很少,但没有一个工作。继承我的onCreate方法:

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        final View view = inflater.inflate(R.layout.fragment_new_pik, container, false);
        ButterKnife.bind(this,view);
        EventBus.getDefault().register(this);

        Category category1 = new Category();
        Category category2 = new Category();
        Category category3 = new Category();
        Category category4 = new Category();
        Category category5 = new Category();

        categories = new ArrayList<>();
        categories.add(category1);
        categories.add(category2);
        categories.add(category3);
        categories.add(category4);
        categories.add(category5);
        adapter = new CategoryAdapter(categories,getActivity().getApplicationContext());

        mScrollView.setAdapter(adapter);
        mScrollView.scrollToPosition(2);
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                mScrollView.findViewHolderForAdapterPosition(2).itemView.callOnClick();
            }
        },1);

        mScrollView.setItemTransformer(new ScaleTransformer.Builder()
                .setMaxScale(1.05f)
                .setMinScale(0.8f)
                .setPivotX(Pivot.X.CENTER) // CENTER is a default one
                .setPivotY(Pivot.Y.BOTTOM) // CENTER is a default one
                .build();


        return view;
    }

这是我的onBindViewHolder:

@Override
    public void onBindViewHolder(final MyViewHolder holder, final int position) {
        Category category = channelList.get(position);

        holder.menuButton.clearBuilders();
        holder.menuButton.setButtonEnum(ButtonEnum.SimpleCircle);
        holder.menuButton.setPiecePlaceEnum(PiecePlaceEnum.DOT_6_3);
        holder.menuButton.setButtonPlaceEnum(ButtonPlaceEnum.SC_6_3);
        holder.menuButton.setDotRadius(0);
        holder.menuButton.setBackground(mContext.getResources().getDrawable(R.drawable.category_empty_icon));
        holder.menuButton.setNormalColor(mContext.getResources().getColor(R.color.transparent));
        holder.menuButton.setShadowEffect(false);


        for (int i = 0; i < holder.menuButton.getButtonPlaceEnum().buttonNumber(); i++) {
            holder.menuButton.addBuilder(new SimpleCircleButton.Builder()
                    .normalColor(mContext.getResources().getColor(R.color.white))
                    .normalImageRes(R.drawable.logo_splash_screen)
                    .listener(new OnBMClickListener() {
                        @Override
                        public void onBoomButtonClick(int index) {
                            mContext.startActivity(new Intent(mContext.getApplicationContext(), AddPikActivity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
                        }
                    }));
        }

    }

请帮忙吗?

0 个答案:

没有答案