Android NestedScrollView showing only one Item in ListView - android

Anyone knows what's wrong in my layout? I'm not able to figure out if why is my ListView is showing only one item.
Layout.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/grey_200"
android:paddingLeft="10dp"
android:paddingRight="10dp"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.rostata.alejo.vbmobileapp.ActivityResult"
tools:showIn="#layout/activity_home">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:id="#+id/one">
<android.support.v7.widget.CardView
android:id="#+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="0dp"
android:background="#color/White"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_marginTop="20dp"
app:cardCornerRadius="4dp"
app:cardElevation="2dp">
<RelativeLayout
android:id="#+id/relativeGridInside"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/White"
android:padding="10dp">
<RelativeLayout
android:id="#+id/headerThisNow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/border_bottom">
<Button
android:id="#+id/btnCloseWordOfTheDay"
style="?android:attr/buttonStyleSmall"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#drawable/ic_window_close"
android:text="" />
<TextView
android:id="#+id/textView9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:fontFamily="sans-serif-light-bold"
android:text="Word of the Day"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/grey_700"
android:textSize="25sp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/headerThisNow">
<TextView
android:id="#+id/wordNow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="5dp"
android:fontFamily="sans-serif-light-bold"
android:text="Paghurop-hurop"
android:textColor="#color/grey_700"
android:textSize="20sp" />
<TextView
android:id="#+id/thisPronounceNow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/wordNow"
android:fontFamily="sans-serip-light"
android:text="-Pag-hu-rop-hu-rop-"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/grey_400"
android:textStyle="italic" />
<TextView
android:id="#+id/maningTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/thisPronounceNow"
android:layout_centerVertical="true"
android:layout_marginTop="10dp"
android:text="Meaning"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
<TextView
android:id="#+id/thisMeaningNow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/maningTitle"
android:ellipsize="end"
android:maxLines="2"
android:text="If ever na mabasa nindu ini, sample lang pu ni, maung comment please"
android:textAppearance="?android:attr/textAppearanceMedium" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/thisMeaningNow"
android:layout_marginTop="10dp">
<Button
android:id="#+id/btnVoice"
style="?android:attr/buttonStyleSmall"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignTop="#+id/btnMore"
android:background="#drawable/ic_voice"
android:padding="0dp"
android:text="" />
<ToggleButton
android:id="#+id/checkBox"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_alignTop="#+id/btnVoice"
android:layout_toEndOf="#+id/btnVoice"
android:layout_toRightOf="#+id/btnVoice"
android:layout_marginLeft="10dp"
android:background="#drawable/toogle_favorite_check"
android:text=""
android:textOff=""
android:textOn="" />
<Button
android:id="#+id/btnMore"
style="?android:attr/buttonStyleSmall"
android:layout_width="100dp"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:background="#drawable/btn_more"
android:text="More"
android:textColor="#color/White" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/card_view"
android:id="#+id/words_list_view"
android:divider="#color/transparent"
android:scrollbars="none"
android:layout_weight="1"/>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
I am using A Fragment Activity and SimpleCusrsorAdapter to populate an items to my ListView. in case of, this is my class;
public class ActivityHome extends Fragment {
CardView cardViewWordOfTheDay;
private WordsDbAdapter dbHelper;
private SimpleCursorAdapter dataAdapter;
private String wordFromSpinner = "ALL";
ListView listView;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.layout, container, false);
Button btnCloseWordOfTheDay = (Button) view.findViewById(R.id.btnCloseWordOfTheDay);
listView = (ListView) view.findViewById(R.id.words_list_view);
btnCloseWordOfTheDay.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
cardViewWordOfTheDay = (CardView) view.findViewById(R.id.card_view);
cardViewWordOfTheDay.setVisibility(View.GONE);
}
});
dbHelper = new WordsDbAdapter(getActivity().getApplicationContext());
dbHelper.open();
displayListView(wordFromSpinner);
return view;
}
private void displayListView(String wordFromSpinnerData) {
Cursor cursor = null;
try {
cursor = dbHelper.fetchAllWords(wordFromSpinnerData);
} catch (Exception e) {
Toast.makeText(getActivity().getApplicationContext(), "EER " + e, Toast.LENGTH_LONG).show();
}
String[] columns = new String[]{
WordsDbAdapter.KEY_ONE, WordsDbAdapter.KEY_TWO,
WordsDbAdapter.KEY_THREE, WordsDbAdapter.KEY_FOUR, WordsDbAdapter.KEY_FIVE
};
int[] to = new int[]{
R.id.thisWord, R.id.thisSub, R.id.thisWordFrom, R.id.thisWordLocation, R.id.thisLetter
};
dataAdapter = new SimpleCursorAdapter(getActivity().getApplicationContext(), R.layout.words_list_item, cursor, columns, to, 0);
listView.setAdapter(dataAdapter);
}
}
I'm so confused. i dont what happen. when i try to change the height of my RelativeLayout to 500dp then the listView is showing the other items but not all. so i think i need it to be wrap_parent but this is not giving me the expected ouput.
Any help would be appreciated. Thank You Very Much!!!

As mentioned here,
You can call this method after listView.setAdapter(dataAdapter);
public static void setListViewHeightBasedOnChildren(ListView listView) {
ListAdapter listAdapter = listView.getAdapter();
if (listAdapter == null)
return;
int desiredWidth = View.MeasureSpec.makeMeasureSpec(
listView.getWidth(), View.MeasureSpec.UNSPECIFIED);
int totalHeight = 0;
View view = null;
for (int i = 0; i < listAdapter.getCount(); i++) {
view = listAdapter.getView(i, view, listView);
if (i == 0)
view.setLayoutParams(new ViewGroup.LayoutParams(
desiredWidth, LayoutParams.WRAP_CONTENT));
view.measure(desiredWidth, View.MeasureSpec.UNSPECIFIED);
totalHeight += view.getMeasuredHeight();
}
ViewGroup.LayoutParams params = listView.getLayoutParams();
params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
listView.setLayoutParams(params);
}

Related

How to make ExpandableListView scroll inside ScrollView and not on itself?

I can’t get the ExpandableListView to scroll inside the ScrollView and not on itself. The problem is that if I change the ExpandableListView to a TextView with a large text, everything works fine. But the ExpandableListView scroll works without a ScrollView.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rootRelativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:id="#+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/footer"
android:layout_marginBottom="0dp"
android:fillViewport="true"
android:scrollbars="none">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/ImageGoods"
android:layout_width="match_parent"
android:layout_height="250dp"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="#drawable/pizza_pepperoni_lovers" />
<TextView
android:id="#+id/ImageViewText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:layout_marginLeft="20dp"
android:layout_alignLeft="#id/ImageGoods"
android:layout_alignTop="#id/ImageGoods"
android:text="NEW Product!!!"
android:textStyle="bold"
android:textColor="#color/Black"
android:textSize="30dp"
android:includeFontPadding="false"
android:background="#color/TextGoodsImageColor"
android:gravity="center"/>
<Button
android:id="#+id/SizeButton1"
android:layout_width="80dp"
android:layout_height="35dp"
android:layout_below="#+id/textView2"
android:layout_alignStart="#+id/textView2"
android:layout_marginStart="0dp"
android:layout_marginTop="5dp"
android:background="#drawable/button_border"
android:text="25mm"
android:textAllCaps="false"
android:textSize="12sp" />
<Button
android:id="#+id/SizeButton2"
android:layout_width="80dp"
android:layout_height="35dp"
android:layout_below="#+id/textView2"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp"
android:layout_toEndOf="#+id/SizeButton1"
android:background="#drawable/button_border"
android:text="30mm"
android:textAllCaps="false"
android:textSize="12sp" />
<Button
android:id="#+id/SizeButton3"
android:layout_width="80dp"
android:layout_height="35dp"
android:layout_below="#+id/textView2"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp"
android:layout_toEndOf="#+id/SizeButton2"
android:background="#drawable/button_border"
android:text="36mm"
android:textAllCaps="false"
android:textSize="12sp" />
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/ImageGoods"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:text="size"
android:textColor="#color/Black"
android:textStyle="bold" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/SizeButton3"
android:layout_marginTop="7dp">
<ExpandableListView
android:id="#+id/lvExp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none"
android:transcriptMode="disabled"/>
</RelativeLayout>
</RelativeLayout>
</ScrollView>
<RelativeLayout
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:background="#color/colorFooter"
android:orientation="vertical" >
<Button
android:id="#+id/btn_add_goods_to_basket"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#android:color/transparent"
android:padding="5dp"
android:text="Add basket"
android:inputType="textFilter"
android:textAlignment="center"
android:layout_alignParentRight="true"
android:textColor="#color/White" />
<Button
android:id="#+id/btn_change_qtty_minus"
android:layout_width="40dp"
android:layout_height="match_parent"
android:layout_marginLeft="7dp"
android:layout_marginTop="7dp"
android:layout_marginBottom="7dp"
android:background="#drawable/plus_minus_button"
android:drawableTop="#drawable/minus"
android:gravity="center_horizontal"
android:padding="5dp"
android:textAlignment="center"
android:textColor="#color/White"
android:textSize="25dp" />
<Button
android:id="#+id/btn_change_qtty_pilus"
android:layout_width="40dp"
android:layout_height="match_parent"
android:layout_marginStart="7dp"
android:layout_marginTop="7dp"
android:layout_marginBottom="7dp"
android:layout_toEndOf="#+id/textView5"
android:background="#drawable/plus_minus_button"
android:gravity="center_horizontal"
android:padding="5dp"
android:drawableTop="#drawable/pilus"
android:textAlignment="center"
android:textColor="#color/White"
android:textSize="25dp" />
<TextView
android:id="#+id/TotalSum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/btn_change_qtty_minus"
android:layout_alignBottom="#+id/btn_change_qtty_minus"
android:layout_marginStart="7dp"
android:layout_marginTop="0dp"
android:layout_marginBottom="0dp"
android:layout_toEndOf="#+id/btn_change_qtty_pilus"
android:textColor="#color/White"
android:gravity="center"
android:text="25$"
android:textStyle="bold" />
<TextView
android:id="#+id/textView5"
android:layout_width="20dp"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/btn_change_qtty_minus"
android:layout_alignBottom="#+id/btn_change_qtty_minus"
android:layout_marginStart="7dp"
android:layout_marginTop="0dp"
android:layout_marginBottom="0dp"
android:layout_toEndOf="#+id/btn_change_qtty_minus"
android:textStyle="bold"
android:textColor="#color/White"
android:gravity="center"
android:text="x1" />
</RelativeLayout>
</RelativeLayout>
This is my xml code.
How can this problem be solved?
Just found the answer to my question.
enter link description here
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.expandable, container, false);
ExpandableAdapter adapter = new ExpandableAdapter();
expandableListView.setAdapter(adapter);
setExpandableListViewHeight(expandableListView, -1);
expandableListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
#Override
public boolean onGroupClick(ExpandableListView parent, View v, int position, long id) {
setExpandableListViewHeight(parent, position);
return false;
}
});
return view;
}
private void setExpandableListViewHeight(ExpandableListView listView,
int group) {
ExpandableListAdapter listAdapter = (ExpandableListAdapter) listView.getExpandableListAdapter();
int totalHeight = 0;
int desiredWidth = View.MeasureSpec.makeMeasureSpec(listView.getWidth(),
View.MeasureSpec.EXACTLY);
for (int i = 0; i < listAdapter.getGroupCount(); i++) {
View groupItem = listAdapter.getGroupView(i, false, null, listView);
groupItem.measure(desiredWidth, View.MeasureSpec.UNSPECIFIED);
totalHeight += groupItem.getMeasuredHeight();
if (((listView.isGroupExpanded(i)) && (i != group))
|| ((!listView.isGroupExpanded(i)) && (i == group))) {
for (int j = 0; j < listAdapter.getChildrenCount(i); j++) {
View listItem = listAdapter.getChildView(i, j, false, null,
listView);
listItem.measure(desiredWidth, View.MeasureSpec.UNSPECIFIED);
totalHeight += listItem.getMeasuredHeight();
}
}
}
ViewGroup.LayoutParams params = listView.getLayoutParams();
int height = totalHeight
+ (listView.getDividerHeight() * (listAdapter.getGroupCount() - 1));
if (height < 10)
height = 200;
params.height = height;
listView.setLayoutParams(params);
listView.requestLayout();
}

How to limit ListView to particular number of list items?

I am working on a functionality in which I have a ListView and I want listView to show only 3 items. I have set ListView height to "wrap_content" and in adapter I have set get count to 3 so that it will show only 3 items but it is showing only 1 item. I am not able to figure out what is happening.My API is returing only 3 items but not able to show all the items in ListView.
Adapter Code:
public class Adapter3Testimonials extends BaseAdapter {
private Activity activity;
private ArrayList<HashMap<String, String>> data;
private static LayoutInflater inflater = null;
private Context context;
public Adapter3Testimonials(Activity a, ArrayList<HashMap<String, String>> d) {
activity = a;
this.data = d;
context = a;
inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public int getCount() {
return data.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(final int position, View convertView, ViewGroup parent) {
View itemView = inflater.inflate(R.layout.item_3_testimonials, parent, false);
TextView txtTestimonial = (TextView) itemView.findViewById(R.id.txtAdvisorTestimonails);
Log.e("TAG", "item_3_testimonials: " + position);
HashMap<String, String> testimonialsList;
testimonialsList = new HashMap<String, String>();
testimonialsList = data.get(position);
txtTestimonial.setText(testimonialsList.get("description"));
return itemView;
}
}
Xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:id="#+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/dp10"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/dp5">
<FrameLayout
android:id="#+id/layImageProfile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="#dimen/dp5"
android:background="#drawable/half_blue_circle">
<de.hdodenhof.circleimageview.CircleImageView xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/profile_image"
android:layout_width="#dimen/dp80"
android:layout_height="#dimen/dp80"
android:padding="#dimen/dp2"
android:src="#drawable/blank_profile" />
<de.hdodenhof.circleimageview.CircleImageView xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/profile_image2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher_background"
android:visibility="gone"
app:civ_border_width="2dp" />
<ImageView
android:id="#+id/imgBlockUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#id/profile_image2"
android:layout_gravity="right"
android:src="#drawable/phone" />
</FrameLayout>
<TextView
android:id="#+id/txtName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="#dimen/dp13"
android:layout_toRightOf="#+id/layImageProfile"
android:text="John doe"
android:textColor="#android:color/black"
android:textSize="#dimen/dp15" />
<TextView
android:id="#+id/txtFirmName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#id/txtName"
android:layout_alignStart="#id/txtName"
android:layout_below="#id/txtName"
android:text="Demo Corp. Inc."
android:textColor="#android:color/black" />
<TextView
android:id="#+id/txtRnf"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#id/txtFirmName"
android:layout_alignStart="#id/txtFirmName"
android:layout_below="#id/txtFirmName"
android:text="Rnf No #12234"
android:textColor="#android:color/black" />
<com.iarcuschin.simpleratingbar.SimpleRatingBar
android:id="#+id/imgReviewStarts"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#id/txtRnf"
android:layout_below="#id/txtRnf"
android:layout_marginTop="#dimen/dp5"
android:layout_toRightOf="#id/layImageProfile"
app:srb_borderColor="#color/colorPrimary"
app:srb_fillColor="#color/colorPrimary"
app:srb_isIndicator="true"
app:srb_numberOfStars="5"
app:srb_starBorderWidth="1.0"
app:srb_starCornerRadius="2.5"
app:srb_starSize="#dimen/dp15"
app:srb_stepSize="1" />
<ImageView
android:id="#+id/imgClickToConnect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="#dimen/dp25"
android:src="#drawable/click" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="#dimen/dp1"
android:layout_marginTop="#dimen/dp10"
android:background="#color/colorPrimary" />
<TextView
android:id="#+id/txtStatement"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/dp5"
android:background="#color/colorPrimary"
android:paddingBottom="#dimen/dp5"
android:paddingLeft="#dimen/dp5"
android:paddingTop="#dimen/dp3"
android:text="Mission statement Lorum ipsum dolar sit or elit lamet,consector cillium"
android:textColor="#android:color/white" />
<View
android:layout_width="match_parent"
android:layout_height="#dimen/dp1"
android:layout_marginTop="#dimen/dp5"
android:background="#color/colorPrimary" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/dp5"
android:paddingLeft="#dimen/dp10"
android:text="#string/customer_review_score"
android:textColor="#android:color/black"
android:textSize="#dimen/dp15" />
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="#dimen/dp10"
android:progress="100"
android:progressTint="#android:color/black" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/dp10"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/buying_exp" />
<com.iarcuschin.simpleratingbar.SimpleRatingBar
android:id="#+id/imgBuyingExp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/txtRnf"
android:layout_marginLeft="#dimen/dp20"
app:srb_borderColor="#color/colorPrimary"
app:srb_fillColor="#color/colorPrimary"
app:srb_isIndicator="true"
app:srb_numberOfStars="5"
app:srb_starBorderWidth="1.0"
app:srb_starCornerRadius="2.5"
app:srb_starSize="#dimen/dp15"
app:srb_stepSize="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/dp10"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/knowledge_comp" />
<com.iarcuschin.simpleratingbar.SimpleRatingBar
android:id="#+id/imgKnowledgeComp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/txtRnf"
android:layout_marginLeft="#dimen/dp20"
app:srb_borderColor="#color/colorPrimary"
app:srb_fillColor="#color/colorPrimary"
app:srb_isIndicator="true"
app:srb_numberOfStars="5"
app:srb_starBorderWidth="1.0"
app:srb_starCornerRadius="2.5"
app:srb_starSize="#dimen/dp15"
app:srb_stepSize="1" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/dp10"
android:orientation="horizontal"
android:weightSum="1">
<TextView
android:id="#+id/txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.9"
android:text="#string/percentage_of_customer" />
<TextView
android:id="#+id/txtPercentageRecommended"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="#dimen/dp20"
android:layout_toRightOf="#id/txt"
android:text="100%" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="#dimen/dp1"
android:layout_marginTop="#dimen/dp10"
android:background="#color/colorPrimary" />
<LinearLayout
android:id="#+id/layTestimonials"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/dp5"
android:background="#color/colorPrimary"
android:orientation="vertical">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="#dimen/dp10"
android:paddingTop="#dimen/dp10"
android:text="#string/customer_testimonials"
android:textColor="#android:color/white"
android:textSize="#dimen/dp15" />
<TextView
android:id="#+id/btnTestimonialNumber"
android:layout_width="#dimen/dp35"
android:layout_height="#dimen/dp35"
android:layout_gravity="center_vertical"
android:layout_marginLeft="#dimen/dp10"
android:layout_marginTop="#dimen/dp5"
android:layout_toRightOf="#id/textView"
android:background="#drawable/round_button"
android:padding="#dimen/dp5"
android:text=""
android:textAlignment="center"
android:textColor="#color/colorPrimary" />
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/textView"
android:paddingLeft="#dimen/dp10"
android:progress="100"
android:progressTint="#android:color/white" />
</RelativeLayout>
<TextView
android:id="#+id/noTestimonial"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="#dimen/dp20"
android:layout_marginTop="#dimen/dp20"
android:gravity="center"
android:text="#string/no_testimonials"
android:textColor="#android:color/white"
android:visibility="gone" />
<ListView
android:id="#+id/listCustomer_testimonial"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/dp10"
android:layout_marginTop="#dimen/dp10"
android:divider="#android:color/white">
</ListView>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="#dimen/dp1"
android:layout_marginTop="#dimen/dp5"
android:background="#color/colorPrimary" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/dp10"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="#dimen/dp5"
android:text="Years of experience:"
android:textColor="#android:color/black" />
<TextView
android:id="#+id/txtAdExperience"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/dp8"
android:text="2" />
</LinearLayout>
<TextView
android:id="#+id/txtExpertise"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="#dimen/dp5"
android:text="#string/expertise"
android:textColor="#android:color/black"
android:visibility="gone" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="#dimen/dp5"
android:orientation="horizontal">
<TextView
android:id="#+id/btnProtect_money"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/dp5"
android:background="#drawable/bg_skyblue"
android:padding="#dimen/dp5"
android:text="#string/protect_money"
android:textAllCaps="false"
android:textColor="#android:color/white"
android:visibility="gone" />
<TextView
android:id="#+id/btnGrow_money"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/dp5"
android:background="#drawable/bg_skyblue"
android:padding="#dimen/dp5"
android:text="#string/grow_money"
android:textColor="#android:color/white"
android:visibility="gone" />
<TextView
android:id="#+id/btnMedical_Needs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/dp5"
android:background="#drawable/bg_skyblue"
android:padding="#dimen/dp5"
android:text="#string/medical_need"
android:textColor="#android:color/white"
android:visibility="gone" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="#dimen/dp15"
android:layout_marginLeft="#dimen/dp10"
android:layout_marginTop="#dimen/dp10">
<TextView
android:id="#+id/txtSocialMedia"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/find_me_on_social_media"
android:textColor="#android:color/black"
android:textSize="#dimen/dp15" />
<ImageView
android:id="#+id/imgFB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/txtSocialMedia"
android:layout_marginTop="#dimen/dp10"
android:src="#drawable/fb_icon" />
<ImageView
android:id="#+id/imgYoutube"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/txtSocialMedia"
android:layout_marginLeft="#dimen/dp5"
android:layout_marginTop="#dimen/dp10"
android:layout_toRightOf="#id/imgFB"
android:src="#drawable/youtube_icon" />
<ImageView
android:id="#+id/imgLinkden"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/txtSocialMedia"
android:layout_marginLeft="#dimen/dp5"
android:layout_marginTop="#dimen/dp10"
android:layout_toRightOf="#id/imgYoutube"
android:src="#drawable/linkedin_icon" />
<ImageView
android:id="#+id/imgRSS"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/txtSocialMedia"
android:layout_marginLeft="#dimen/dp5"
android:layout_marginTop="#dimen/dp10"
android:layout_toRightOf="#id/imgLinkden"
android:src="#drawable/rss_icon" />
<ImageView
android:id="#+id/imgCartoon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_toRightOf="#id/txtSocialMedia"
android:src="#drawable/man_after_feedback" />
<ImageView
android:id="#+id/imgRead_my_articles"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_below="#id/imgFB"
android:layout_marginTop="#dimen/dp10"
android:src="#drawable/read_my_articles" />
<ImageView
android:id="#+id/imgClick_for_feedback"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#id/imgFB"
android:layout_marginRight="#dimen/dp10"
android:layout_marginTop="#dimen/dp10"
android:src="#drawable/click_for_feedback" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
<ProgressBar
android:id="#+id/pBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:visibility="gone" />
Inside this code I have ListView with id "listCustomer_testimonial".
Never use ListView inside Scrollview. But if you must use ListView inside ScrollView create a scrollhandler.
public class scrollhandler {
public static void getListViewSize(ListView myListView) {
ListAdapter myListAdapter = myListView.getAdapter();
if (myListAdapter == null) {
//do nothing return null
return;
}
//set listAdapter in loop for getting final size
int totalHeight = 0;
int rowheight=56;
for (int size = 0; size < myListAdapter.getCount(); size++) {
View listItem = myListAdapter.getView(size, null, myListView);
listItem.measure(0, 0);
totalHeight += listItem.getMeasuredHeight();
rowheight=listItem.getMeasuredHeight();
}
//setting listview item in adapter
ViewGroup.LayoutParams params = myListView.getLayoutParams();
params.height = totalHeight + (myListView.getDividerHeight() * (myListAdapter.getCount() - 1));
myListView.setLayoutParams(params);
// print height of adapter on log
Log.i("height of listItem:", String.valueOf(totalHeight)+","+myListAdapter.getCount());
}
}
Then lastly bind the ListView with the Handler
lv.setAdapter(adapter);
scrollhandler.getListViewSize(lv);
Your problem is not with the getCount() method or list items count.
You have used listview inside scrollview, so only one item will be visible and others can be seen on scroll.
You can use custom Listview to avoid issue in height of listview,
public class NonScrollableListview extends ListView {
public NonScrollableListview(Context context) {
super(context);
}
public NonScrollableListview(Context context, AttributeSet attrs) {
super(context, attrs);
}
public NonScrollableListview(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
#Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int heightMeasureSpec_custom = MeasureSpec.makeMeasureSpec(
Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, heightMeasureSpec_custom);
ViewGroup.LayoutParams params = getLayoutParams();
params.height = getMeasuredHeight();
}
}
In your xml ,
<com.yourpack.NonScrollableListview
android:id="#+id/list_detail"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Or use NestedScrollView with RecyclerView instead of listview.
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:fillViewport="true">
<!--otherviews-->
<android.support.v7.widget.RecyclerView
android:id="#+id/list_detail"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<!--otherviews-->
</android.support.v4.widget.NestedScrollView>

Set ListView Height programmatically in Android

I have a ListView in my activity's Layout that exists in a ScrollView like that:
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical">
<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:layout_marginBottom="4dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="4dp"
android:orientation="vertical"
android:padding="4dp">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:gravity="center_vertical|center_horizontal"
android:padding="5dp"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/white" />
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:padding="5dp"
android:visibility="gone" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#color/article_title"
android:gravity="center_vertical|center_horizontal"
android:padding="5dp"
android:text="#string/add_to_my_resources"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/white" />
</LinearLayout>
<LinearLayout
android:id="#+id/buttons_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:background="#color/white"
android:orientation="vertical">
<LinearLayout
android:id="#+id/article_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
style="#style/Widget.AppCompat.Button.Borderless.Colored"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#color/article_title"
android:gravity="center_vertical|center_horizontal"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/white" />
<Button
style="#style/Widget.AppCompat.Button.Borderless.Colored"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical|center_horizontal"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/white" />
</LinearLayout>
<ListView
android:id="#+id/authors_listView"
android:layout_width="wrap_content"
android:layout_height="match_parent">
</ListView>
<ExpandableListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:divider="#color/light_gray"
android:dividerHeight="0.5dp"
android:groupIndicator="#null"
android:scrollbars="none"
android:textAlignment="center">
</ExpandableListView>
</LinearLayout>
</LinearLayout>
</ScrollView>
And I have a List Adapter names MyListAdapter that populate my listview:
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
LayoutInflater inflater = mcontex.getLayoutInflater();
if (convertView == null)
{
convertView = inflater.inflate(R.layout.my_list, null);
holder = new ViewHolder();
holder.txtViewName = (TextView) convertView.findViewById(R.id.textView1);
holder.txtViewAff = (TextView) convertView.findViewById(R.id.textView2);
convertView.setTag(holder);
}
else
{
holder = (ViewHolder) convertView.getTag();
}
holder.txtViewName.setGravity(Gravity.LEFT);
holder.txtViewName.setText(name.get(position));
if (aff != null) {
holder.txtViewAff.setGravity(Gravity.LEFT);
holder.txtViewAff.setText(aff.get(position));
}
return convertView;
}
And my_list.xml is:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="20dp">
<TextView
android:id="#+id/textView1"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:textAppearance="?android:attr/textAppearanceLarge">
</TextView>
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/textView1">
</TextView>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
app:srcCompat="#drawable/ic_draw"/>
</RelativeLayout>
I want to set listview height dynamically to avoid scrolling list view inside the parent layout. So I use this method:
public static void setListViewHeightBasedOnChildren(ListView listView) {
AuthorsListAdapter listAdapter = (AuthorsListAdapter) listView.getAdapter();
if (listAdapter == null)
return;
int desiredWidth = View.MeasureSpec.makeMeasureSpec(listView.getWidth(), View.MeasureSpec.UNSPECIFIED);
int totalHeight=0;
View view = null;
for (int i = 0; i < listAdapter.getCount(); i++)
{
view = listAdapter.getView(i, view, listView);
if (i == 0)
view.setLayoutParams(new ViewGroup.LayoutParams(desiredWidth,
LinearLayoutCompat.LayoutParams.MATCH_PARENT));
view.measure(desiredWidth, View.MeasureSpec.UNSPECIFIED);
totalHeight += view.getMeasuredHeight();
}
ViewGroup.LayoutParams params = listView.getLayoutParams();
params.height = totalHeight + ((listView.getDividerHeight()) * (listAdapter.getCount()));
listView.setLayoutParams(params);
listView.requestLayout();
}
This method works correctly in normal but when txtViewAff value is more than 2 or 3 lines, the last item of listview goes behind of the ExpandableListView. I add constant value like 40 to my totalHeight in method setListViewHeightBasedOnChildren:
totalHeight += view.getMeasuredHeight() + 40;
but it adds some blank space for normal items that were true without adding 40.
What can I do to resolve this problem?

Hide a Relativelayout in recyclerview

I am using this liabray for swipe gestures. https://github.com/nikhilpanju/RecyclerViewEnhanced.
Activity:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_admin_panel);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
unclickableRows = new ArrayList<>();
unswipeableRows = new ArrayList<>();
dialogItems = new String[25];
for (int i = 0; i < 25; i++) {
dialogItems[i] = String.valueOf(i + 1);
}
mRecyclerView = (RecyclerView) findViewById(R.id.recyclerView);
mAdapter = new MainAdapter(this, getData());
mRecyclerView.setAdapter(mAdapter);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
onTouchListener = new RecyclerTouchListener(this, mRecyclerView);
onTouchListener
.setIndependentViews(R.id.rowButton)
.setViewsToFade(R.id.rowButton)
.setClickable(new RecyclerTouchListener.OnRowClickListener() {
#Override
public void onRowClicked(int position) {
util.shortToast(getApplicationContext(), "Row " + (position + 1) + " clicked!");
}
#Override
public void onIndependentViewClicked(int independentViewID, int position) {
util.shortToast(getApplicationContext(), "Button in row " + (position + 1) + " clicked!");
}
})
.setSwipeOptionViews(R.id.add, R.id.edit, R.id.change)
.setSwipeable(R.id.rowFG, R.id.rowBG, new RecyclerTouchListener.OnSwipeOptionsClickListener() {
#Override
public void onSwipeOptionClicked(int viewID, int position) {
String message = "";
if (viewID == R.id.add) {
message += "Add";
} else if (viewID == R.id.edit) {
message += "Edit";
} else if (viewID == R.id.change) {
message += "Change";
}
message += " clicked for row " + (position + 1);
util.shortToast(getApplicationContext(), message);
}
});
mRecyclerView.addOnItemTouchListener(onTouchListener);
In below code, i want to hide a Relativelayout when in onSwipeOptionclicked() function the viewID == R.id.add. I modified code to get reference but don't know what to do next.
.setSwipeOptionViews(R.id.add, R.id.edit, R.id.change)
.setSwipeable(R.id.rowFG, R.id.rowBG, new RecyclerTouchListener.OnSwipeOptionsClickListener() {
#Override
public void onSwipeOptionClicked(int viewID, int position) {
if (viewID == R.id.add) {
}
}
});
Modified code:
.setSwipeOptionViews(R.id.add, R.id.edit, R.id.change)
.setSwipeable(R.id.rowFG, R.id.rowBG, new RecyclerTouchListener.OnSwipeOptionsClickListener() {
#Override
public void onSwipeOptionClicked(int viewID, int position) {
if (viewID == R.id.add) {
RelativeLayout username = (RelativeLayout) view.findViewById(R.id.add);
}
}
});
Relativelayout XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="#+id/rowBG"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:orientation="horizontal">
<RelativeLayout
android:id="#+id/add"
android:layout_width="#dimen/swipeWidth"
android:layout_height="match_parent"
android:background="#color/swipeoption_blue"
android:clickable="true"
android:focusable="true"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:background="?android:selectableItemBackground"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="#drawable/ic_add_black_24dp"
android:tint="#android:color/white"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="4dp"
android:ellipsize="end"
android:gravity="center"
android:maxLines="1"
android:text="Add"
android:textColor="#android:color/white"
android:textSize="12sp"/>
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:id="#+id/edit"
android:layout_width="#dimen/swipeWidth"
android:layout_height="match_parent"
android:background="#color/swipeoption_green"
android:clickable="true"
android:focusable="true"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:background="?android:selectableItemBackground"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="#drawable/ic_mode_edit_black_24dp"
android:tint="#android:color/white"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="4dp"
android:ellipsize="end"
android:gravity="center"
android:maxLines="1"
android:text="Edit"
android:textColor="#android:color/white"
android:textSize="12sp"/>
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:id="#+id/delete"
android:layout_width="#dimen/swipeWidth"
android:layout_height="match_parent"
android:background="#color/swipeoption_purple"
android:clickable="true"
android:focusable="true"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:background="?android:selectableItemBackground"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:tint="#android:color/white"
app:srcCompat="#drawable/ic_build_black_24dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:id="#+id/delete_user"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="4dp"
android:ellipsize="end"
android:gravity="center"
android:maxLines="1"
android:text="Delete"
android:textColor="#android:color/white"
android:textSize="12sp"/>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/rowFG"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white"
android:clickable="true"
android:elevation="4dp"
android:focusable="true"
android:orientation="horizontal"
android:visibility="visible">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:orientation="horizontal"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingTop="16dp">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="6"
android:orientation="vertical">
<TextView
android:id="#+id/mainText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:text="No Calls Found"
android:textSize="16sp"
android:textStyle="bold"
tools:text="Row 1"/>
<TextView
android:id="#+id/subText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:maxLines="1"
tools:text="Some text ..."/>
</LinearLayout>
<Button
android:id="#+id/rowButton"
style="?attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center_vertical"
android:gravity="right|center_vertical"
android:text="Button"/>
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_alignParentBottom="true"
android:background="#67676767"
android:elevation="5dp"/>
</RelativeLayout>
username.setVisibility(View.GONE);
For anybody who looking for solution how close\hide RelativeLayout programmatically in android.
I have a DrawerLayout as parent of RelativeLayout, so, this solution work for me:
DrawerLayout dl = findViewById(R.id.drawer_layout);
dl.closeDrawers();

What's the difference between listview item and listview footer in rendering life cycle?

I have a listview contains items and footer views. Items layout works as it should, but footer's layout doesn't work like item views...
I could't understand where my fault is.
This is my item's layout xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/lstCardItem"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#drawable/pm_dashboard_cardshadow" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5.33dp"
android:layout_marginLeft="11.67dp"
android:layout_marginRight="11.67dp"
android:layout_marginTop="6dp" >
<ImageView
android:id="#+id/ivCard"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:animateLayoutChanges="true"
android:scaleType="fitXY" />
<com.controls.DynamicResizeImageView
android:id="#+id/ivCardLock"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:background="#drawable/pm_dashboard_cardmask"
android:scaleType="center"
android:src="#drawable/selector_btn_dashboard_lock" />
<LinearLayout
android:id="#+id/llInfo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:gravity="top|right"
android:orientation="vertical"
android:paddingLeft="18dp"
android:paddingRight="18dp"
android:visibility="visible" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center|right"
android:gravity="center|right"
android:orientation="horizontal"
android:paddingBottom="4dp"
android:paddingTop="4dp" >
<TextView
android:id="#+id/tvCardBalance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/tvCurrency"
android:gravity="top"
android:text="10,344"
android:textColor="#color/white"
android:textSize="18dp"
android:typeface="serif" />
<TextView
android:id="#+id/tvCurrency"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="3dp"
android:layout_marginTop="2dp"
android:gravity="top"
android:text="#string/global_currency"
android:textColor="#color/white"
android:textSize="10dp"
android:typeface="sans" />
<TextView
android:id="#+id/tvCardBalanceName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="#string/pgDashboard_lblBalanceBanner"
android:textColor="#color/white"
android:textSize="11.33dp"
android:typeface="monospace" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/pm_dashboard_seam" />
</LinearLayout>
For my businness side lifecycle:
private void refreshCards() {
if (applyButtons != null)
DashboardFragment.this.lvCards.removeFooterView(applyButtons);
applyButtons = new LinearLayout(getActivity());
applyButtons.setTag("FOOTER");
applyButtons.setOrientation(LinearLayout.VERTICAL);
AbsListView.LayoutParams LLParams = new AbsListView.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
applyButtons.setLayoutParams(LLParams);
if (ininalCount < 32) {
View createNewCardButton = getApplyButtonView(R.string.pgDashboard_lblCreateIninalCard, R.drawable.pm_dashboard_card_yenikartolustur, R.drawable.pm_dashboard_arrow_icon, new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(getActivity(), CreateNewCardActivity.class);
startActivity(intent);
}
});
View AddCard = getApplyButtonView(R.string.pgDashboard_lblAddCard, R.drawable.pm_dashboard_card_yenikartekle, R.drawable.pm_dashboard_plus_icon, new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(getActivity(), AddCardActivity.class);
startActivity(intent);
}
});
applyButtons.addView(createNewCardButton);
applyButtons.addView(AddCard);
}
final View applyIngCard = getApplyButtonView(R.string.pgDashboard_lblApplyToIngCard, R.drawable.pm_dashboard_card_orange, R.drawable.pm_dashboard_arrow_icon, new View.OnClickListener() {
#Override
public void onClick(View v) {
CardApplicationActivity.Synchronizer.synchronize((BaseActivity) getActivity(), new OnSyncCompletedListener() {
#Override
public void onSyncCompleted() {
Intent intent = new Intent(getActivity(), CardApplicationActivity.class);
startActivity(intent);
}
});
}
});
applyButtons.addView(applyIngCard);
View view = new View(getActivity());
view.setLayoutParams(new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 20, getResources().getDisplayMetrics())));
view.setBackgroundResource(getResources().getColor(R.color.transparent));
applyButtons.addView(view);
bindAdapter();
}
private View getApplyButtonView(int stringId, int backgroundId, int iconId, View.OnClickListener onClickListener) {
final View view = inflater.inflate(R.layout.dashboard_list_card_item, null);
return view;
}
public void bindAdapter() {
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
DashboardFragment.this.lvCards.setLayoutTransition(new LayoutTransition());
DashboardFragment.this.lvCards.addFooterView(applyButtons, null, false);
if (adapter == null) {
adapter = new CardListAdapter(getActivity(), R.layout.dashboard_list_card_item, productModelContainerList);
controller = new CardListController(lvCards);
lvCards.setDropListener(this);
controller.setDragInitMode(CardListController.ON_LONG_PRESS);
lvCards.setFloatViewManager(controller);
lvCards.setOnTouchListener(controller);
lvCards.setAdapter(adapter);
}
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
DashboardFragment.this.lvCards.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
DashboardFragment.this.lvCards.setLayoutTransition(null);
}
}
Here i made some changes,, use these and let me know... otherwise i need your drawable resources to set this.
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/lstCardItem"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#color/background_holo_dark" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5.33dp"
android:layout_marginLeft="11.67dp"
android:layout_marginRight="11.67dp"
android:layout_marginTop="6dp" >
<ImageView
android:id="#+id/ivCard"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:animateLayoutChanges="true"
android:scaleType="fitXY" />
<ImageView
android:id="#+id/ivCardLock"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:background="#color/background_holo_light"
android:scaleType="center"
android:src="#color/bgColor" />
<LinearLayout
android:id="#+id/llInfo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/cropBG"
android:gravity="top|right"
android:orientation="vertical"
android:paddingLeft="18dp"
android:paddingRight="18dp"
android:visibility="visible" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="right|center_horizontal"
android:gravity="center|right"
android:orientation="horizontal"
android:paddingBottom="4dp"
android:paddingTop="4dp" >
<TextView
android:id="#+id/tvCardBalance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/tvCurrency"
android:gravity="top"
android:text="10,344"
android:textColor="#android:color/white"
android:textSize="18dp"
android:typeface="serif" />
<TextView
android:id="#+id/tvCurrency"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="3dp"
android:layout_marginTop="2dp"
android:gravity="top"
android:text="Currency"
android:textColor="#android:color/white"
android:textSize="10dp"
android:typeface="sans" />
<TextView
android:id="#+id/tvCardBalanceName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="pgDashboard_lblBalanceBanner"
android:textColor="#android:color/white"
android:textSize="11.33dp"
android:typeface="monospace" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/bottom_btn_bg_color" />
</LinearLayout>

Categories

Resources