Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Button appears in android API 19, but not API 17

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)

enter image description here

Android 4.4.2(API 17)

enter image description here

like image 426
John Joe Avatar asked Jun 08 '26 18:06

John Joe


2 Answers

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);
    }
}
like image 72
Eric B. Avatar answered Jun 10 '26 06:06

Eric B.


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"/>
  1. In your xml you added hard-coded large value,which are't showing small device .

  2. 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);
like image 31
IntelliJ Amiya Avatar answered Jun 10 '26 06:06

IntelliJ Amiya