Currently, I'm using Android 4.4.2(API 19) to run my project and I can see all the layout works perfectly. But when I use another device Android 4.2(API 17), the layout is running and some of the buttons did not show (footer layout) !!! How can I solve this? Did you guys face this problem before? Thanks.
ListView Button
These are the buttons in xml that did not show when I was using Android API 17. Just a normal button. They should show when there is a listView but they did not.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/totalHours"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/hours"
android:paddingRight="10dp"
android:text=" Total Hours : "
android:textColor="@color/blue"
android:textSize="16sp"/>
<TextView
android:id="@+id/hours"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/submit"
android:paddingRight="15dp"
android:textColor="@color/blue"
android:textSize="16sp"/>
<Button
android:id="@+id/submit"
android:layout_width="334dp"
android:layout_height="61dp"
android:layout_alignParentLeft="true"
android:layout_below="@+id/addClaims1"
android:layout_marginLeft="15dp"
android:text="submit"
android:theme="@style/ButtonTheme"/>
<Button
android:id="@+id/addClaims1"
android:layout_width="334dp"
android:layout_height="61dp"
android:layout_marginTop="10dp"
android:layout_below="@id/totalHours"
android:layout_marginLeft="15dp"
android:text="add claims"/>
</RelativeLayout>
Android 4.4.2(API 19)

Android 4.4.2(API 17)

You must call addFooterView before setting the adapter to the ListView.
EDIT:
Modify your code, such that you set the footerView before setting the adapter like this:
Activity A
footerLayout = (RelativeLayout) getLayoutInflater().inflate(R.layout.under_list_view_button, null);
btnAddClaims = (Button) footerLayout.findViewById(R.id.addClaims1);
btnSubmit=(Button)footerLayout.findViewById(R.id.submit);
objMyCustomBaseAdapter = new MyCustomBaseAdapter(getApplicationContext(), results, listview, footerLayout);
addOrRemoveFooter();
listview.setAdapter(objMyCustomBaseAdapter);
public void addOrRemoveFooter(){
if(results.size() == 0 && listview.getFooterViewsCount() > 0){
// listview.removeFooterView(footer);
listview.removeFooterView(footerLayout);
}else if(listview.getFooterViewsCount() == 0 && results.size() > 0){
// listview.addFooterView(footer);
listview.addFooterView(footerLayout);
}
}
Actually Its your XML Problem .You need to rectify your XML .
Why This Problem
Problem is your Button Section .
<Button
android:id="@+id/submit"
android:layout_width="334dp"
android:layout_height="61dp"
android:layout_alignParentLeft="true"
android:layout_below="@+id/addClaims1"
android:layout_marginLeft="15dp"
android:text="submit"
android:theme="@style/ButtonTheme"/>
<Button
android:id="@+id/addClaims1"
android:layout_width="334dp"
android:layout_height="61dp"
android:layout_marginTop="10dp"
android:layout_below="@id/totalHours"
android:layout_marginLeft="15dp"
android:text="add claims"/>
In your xml you added hard-coded large value,which are't showing small device .
Avoid Hard-coded Value . android:layout_height="61dp" & android:layout_marginTop=10dp" .
You can use layout_weight attribute .
You can set a weight attribute using a float value for any view that you use in a LinearLayout. Android will then divide the available space up amongst the views proportionately, depending on their weight values.
LinearLayout also supports assigning a weight to individual children with the android:layout_weight attribute. This attribute assigns an "importance" value to a view in terms of how much space it should occupy on the screen.
A larger weight value allows it to expand to fill any remaining space in the parent view. Child views can specify a weight value, and then any remaining space in the view group is assigned to children in the proportion of their declared weight. Default weight is zero.
Or You can use DisplayMetrics
/*
* A structure describing general information about a display, such as its size, density, and font scaling.
* */
DisplayMetrics metrics = getResources().getDisplayMetrics();
int DeviceTotalWidth = metrics.widthPixels;
int DeviceTotalHeight = metrics.heightPixels;
LinearLayout LL_First_Section=(LinearLayout)findViewById(R.id.LinearLayout_Third_Invisible);
LL_First_Section.getLayoutParams().width=DeviceTotalWidth; // Add your width
LL_First_Section.getLayoutParams().height= (DeviceTotalHeight*18/100);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With