Example usage for android.view ViewGroup removeView

List of usage examples for android.view ViewGroup removeView

Introduction

In this page you can find the example usage for android.view ViewGroup removeView.

Prototype

@Override
public void removeView(View view) 

Source Link

Document

Note: do not invoke this method from #draw(android.graphics.Canvas) , #onDraw(android.graphics.Canvas) , #dispatchDraw(android.graphics.Canvas) or any related method.

Usage

From source file:com.popdeem.sdk.uikit.fragment.PDUIWalletFragment.java

@Nullable
@Override//from   w ww  .  j a v  a2s.  c o m
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (mView == null) {
        mView = inflater.inflate(R.layout.fragment_pd_wallet, container, false);

        mNoItemsInWalletView = mView.findViewById(R.id.pd_wallet_no_items_view);
        mNoItemsInWalletView.setVisibility(View.GONE);
        mSwipeRefreshLayout = (PDUISwipeRefreshLayout) mView;
        mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                refreshWallet();
            }
        });

        final RecyclerView recyclerView = (RecyclerView) mView.findViewById(R.id.pd_wallet_recycler_view);

        mAdapter = new PDUIWalletRecyclerViewAdapter(mRewards);
        mAdapter.setOnItemClickListener(new PDUIWalletRecyclerViewAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View v) {
                final int position = recyclerView.getChildAdapterPosition(v) - 1;

                if (mRewards.get(position) instanceof PDReward) {
                    final PDReward reward = (PDReward) mRewards.get(position);
                    if (reward.claimedUsingNetwork(PDReward.PD_SOCIAL_MEDIA_TYPE_INSTAGRAM)
                            && !reward.isInstagramVerified()) {
                        return;
                    }

                    if (reward.getCredit() != null && reward.getCredit().length() > 0) {
                        return;
                    }

                    AlertDialog.Builder builder = new AlertDialog.Builder(
                            new ContextThemeWrapper(getActivity(), R.style.AlertDialogCustom));
                    if (reward.getRewardType().equalsIgnoreCase(PDReward.PD_REWARD_TYPE_SWEEPSTAKE)) {
                        String message = String.format(Locale.getDefault(), "%1s",
                                getString(R.string.pd_redeem_sweepstake_reward_info_message_string));
                        builder.setTitle(R.string.pd_redeem_sweepstake_reward_info_title_string)
                                .setMessage(message).setPositiveButton(android.R.string.ok, null);
                        builder.create().show();
                    } else if (!reward.getRewardType().equalsIgnoreCase(PDReward.PD_REWARD_TYPE_CREDIT)) {
                        String message = getString(R.string.pd_wallet_coupon_info_message_text);
                        builder.setTitle(R.string.pd_redeem_reward_info_title_string).setMessage(message)
                                .setNegativeButton(android.R.string.cancel, null)
                                .setPositiveButton(R.string.pd_redeem_button_string,
                                        new DialogInterface.OnClickListener() {
                                            @Override
                                            public void onClick(DialogInterface dialog, int which) {
                                                redeemReward(reward, position);
                                                Intent intent = new Intent(getActivity(),
                                                        PDUIRedeemActivity.class);
                                                intent.putExtra("imageUrl", reward.getCoverImage());
                                                intent.putExtra("reward", reward.getDescription());
                                                intent.putExtra("rules", reward.getRules());
                                                intent.putExtra("isSweepstakes", reward.getRewardType()
                                                        .equalsIgnoreCase(PDReward.PD_REWARD_TYPE_SWEEPSTAKE));
                                                intent.putExtra("time", reward.getAvailableUntilInSeconds());
                                                intent.putExtra("countdown", reward.getCountdownTimer());
                                                startActivity(intent);
                                            }
                                        });
                        builder.create().show();
                    }
                }
            }

            @Override
            public void onVerifyClick(int position) {
                PDReward reward = (PDReward) mRewards.get(position);
                reward.setVerifying(true);
                //                    mAdapter.notifyItemChanged(position);
                mAdapter.notifyDataSetChanged();
                verifyReward(position);
            }
        });

        //            LinearLayoutManager linearLayoutManager = new LinearLayoutManager(container.getContext());
        PDUILinearLayoutManager linearLayoutManager = new PDUILinearLayoutManager(container.getContext());
        mSwipeRefreshLayout.addLinearLayoutManager(linearLayoutManager);

        recyclerView.setLayoutManager(linearLayoutManager);
        //            recyclerView.addItemDecoration(new PDUIDividerItemDecoration(getActivity(), R.color.pd_wallet_list_divider_color, false));
        recyclerView.setAdapter(mAdapter);

        //            refreshWallet();
    } else {
        container.removeView(mView);
    }

    return mView;
}