android - How to Hide view of a button in Adapter? -
i need use same listview & item 2 different fragment modification.
here (screenshot), (need use in different fragment)
- i need show add wishlist & remove in 1st layout & 1st fragment
- i need hide add wishlist & remove in 2nd layout & 2nd fragment
i need use same adapter.
how this?
update
cart_list_item.xml
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:descendantfocusability="blocksdescendants" android:orientation="vertical"> <android.support.v7.widget.cardview xmlns:android="http://schemas.android.com/apk/res/android" xmlns:card_view="http://schemas.android.com/apk/res-auto" android:id="@+id/cardlist_item" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginbottom="12dp" android:layout_marginleft="5dp" android:layout_marginright="5dp" android:background="@drawable/curved_shape" android:orientation="vertical" card_view:cardelevation="2dp"> <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/white" android:orientation="horizontal"> <imageview android:layout_width="80dp" android:layout_height="80dp" android:layout_margin="14dp" android:layout_marginright="14dp" android:src="@drawable/image_4" /> <linearlayout android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_margin="12dp" android:orientation="vertical"> <textview android:id="@+id/cartproduct" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margintop="8dp" android:text="fusce veh" android:textcolor="#9f9f9f" /> <textview android:id="@+id/cartquantity" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margintop="8dp" android:text="100 g" android:textcolor="#9f9f9f" /> <linearlayout android:layout_width="225dp" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:orientation="horizontal" android:weightsum="1"> <textview android:id="@+id/symbol" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margintop="8dp" android:text="rs " android:textcolor="#9f9f9f" /> <textview android:id="@+id/cartprice" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginright="10dp" android:layout_margintop="8dp" android:layout_weight="0.45" android:text="19.99" android:textcolor="#9f9f9f" /> <textview android:id="@+id/cartpricedum" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginright="10dp" android:layout_margintop="8dp" android:layout_weight="0.45" android:text="19.99" android:textcolor="#9f9f9f" android:visibility="gone" /> <imageview android:id="@+id/ivdecrease" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginleft="10dp" android:layout_weight="0.1" android:focusable="false" android:focusableintouchmode="false" android:src="@drawable/ic_action_expand" /> <textview android:id="@+id/cartcount" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginleft="1dp" android:layout_marginright="1dp" android:layout_weight="0.2" android:gravity="center" android:text="1" android:textsize="15dp" android:textstyle="bold" /> <imageview android:id="@+id/ivincrease" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="0.1" android:focusable="false" android:focusableintouchmode="false" android:src="@drawable/ic_action_collapse" /> </linearlayout> </linearlayout> </linearlayout> <view android:layout_width="match_parent" android:layout_height="1dip" android:background="#e4e4e4" /> <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#f8f8f8" android:descendantfocusability="blocksdescendants" android:orientation="horizontal" android:weightsum="1"> <button android:id="@+id/addtowish" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="0.5" android:background="#f8f8f8" android:focusable="false" android:focusableintouchmode="false" android:text="add wishlist" android:textcolor="#787878" /> <view android:layout_width="1dip" android:layout_height="match_parent" android:background="#e4e4e4" /> <button android:id="@+id/remove" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="0.5" android:background="#f8f8f8" android:focusable="false" android:focusableintouchmode="false" android:text="remove" android:textcolor="#787878" /> </linearlayout> </linearlayout> </android.support.v7.widget.cardview> </linearlayout>
use condition based on have use in adapter :
holder.textview1.setvisibility(view.visible); holder.textview2.setvisibility(view.gone);
check :
when add fragment in transaction should use tag.
fragtrans.replace(android.r.id.content, myfragment, "my_fragment");
later if want check if fragment visible:
myfragment myfragment = (myfragment)getfragmentmanager().findfragmentbytag("my_fragment"); if (myfragment != null && myfragment.isvisible()) { // add code here }
once current fragment, can fragment adapter class called.
Comments
Post a Comment