sooorajjj / KOT

Simple shopping cart Application
0 stars 1 forks source link

Any ideas on How to hide views in fragment unless there is an update ? #3

Open sooorajjj opened 8 years ago

sooorajjj commented 8 years ago

At the moment the tablayout-> Fragment looks like this

image

https://github.com/sooorajjj/KOT/blob/master/app/src/main/java/online/klok/kot/shopping_cart/CartFragment.java

` tvTotalItems = (TextView) view.findViewById(R.id.tv_total_items);

    tvTotalPrice = (TextView) view.findViewById(R.id.tv_total_price);
    tvTotalCartAmt = (TextView) view.findViewById(R.id.tv_total_cart_amt);
    rvShoppingCart = (RecyclerView) view.findViewById(R.id.rv_shopping_cart);
    etKitchenNote = (EditText) view.findViewById(R.id.etKitchenNote);
    btnType = (Button) view.findViewById(R.id.btn_type);
    btnSendToKitchen = (Button) view.findViewById(R.id.btnSendToKitchen);
    rvShoppingCart.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false));
    adapter = new ShoppingCartAdapter(this, getShoppingCartItems());

rvShoppingCart.setAdapter(adapter);`

what i am trying to do is set all this views to gone unless there is an update in cart fragment

Also trying to create a Badge on Cart tab title so that it would update when there is a change in CartFragment

image

would look same just with Text instead of icon there

@pocheshire @martinwithaar @eneim @creativetrendsapps

sooorajjj commented 8 years ago

@NileshJarad

creativetrendsapps commented 8 years ago

lol, why am I tagged in this? Anyway, why not (in XML) set the views that you want hidden "gone". android:visibility="gone" and in code when something changes or refreshes, .....View.VISIBLE.

sooorajjj commented 8 years ago

@creativetrendsapps thanks ill try that

sooorajjj commented 8 years ago

@creativetrendsapps tried this

` if (currentCartCount == 0){ btnSendToKitchen.setVisibility(View.GONE);

     }else {
         btnSendToKitchen.setVisibility(View.VISIBLE);
     }`

but the visibility always remains gone :cry:

sooorajjj commented 8 years ago

Finally fixed the Visibility of view

` tvTotalCartAmt.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

            if (currentCartCount == 0) {

                btnSendToKitchen.setVisibility(View.GONE);
                etKitchenNote.setVisibility(View.GONE);
                btnType.setVisibility(View.GONE);
                tvType.setVisibility(View.GONE);
                rvShoppingCart.setVisibility(View.GONE);
                tvTotalCartAmt.setVisibility(View.GONE);
                tvNoCartItems.setVisibility(View.VISIBLE);

            } else {

                btnSendToKitchen.setVisibility(View.VISIBLE);
                etKitchenNote.setVisibility(View.VISIBLE);
                btnType.setVisibility(View.VISIBLE);
                tvType.setVisibility(View.VISIBLE);
                rvShoppingCart.setVisibility(View.VISIBLE);
                tvTotalCartAmt.setVisibility(View.VISIBLE);
                tvNoCartItems.setVisibility(View.GONE);

            }

        }`

had to add addTextChangedListener for it to work fix commit dd4388d5171ea4edd2c79f6a1a7a456f2c240d31

creativetrendsapps commented 8 years ago

This should be closed.

sooorajjj commented 8 years ago

@creativetrendsapps the other half of the question isn't answered . About creating a Badge on Cart tab title so that it would update when there is a change in CartFragment .

sooorajjj commented 8 years ago

@creativetrendsapps Awesome , thanks m8 :)