Motorola Droid2 problem with listview default behaviour

Have you tested your application on all the Android devices ? If you dint then you might be in risk. Some devices in android uses device custom theme to render all its application. Let me explain this with Motorola Droid2 device. I am trying to add a simple ListView in my app. Here is the code which i used to generate it.

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent" >
 <ListView 
 android:layout_width="wrap_content"
 android:layout_height="match_parent"
 android:id="@+id/my_list"
 >

</ListView>
</RelativeLayout>

DroidFixes.java

public class DroidFixes extends Activity {
 CustomAlertDialog dialog;
 ListView list;
 @Override
 public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 String s[] ={"1","2","3"};
 setContentView(R.layout.activity_main);
 list = (ListView)findViewById(R.id.my_list);
 ArrayAdapter<String> arr = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_dropdown_item_1line,s);
 list.setAdapter(arr);
 }
}

This results in :

PROBLEM :

If you closely observer you would’ve found a grey background in the lower half of the ListView. This will not be seen in other devices are even in the emulator. This is the custom behavior of ListView which is implemented in Motorola Droid2. This happen because in the above xml layout ListView’s height is specified as wrap_content.

SOLUTION :

To avoid this there are many solution

  1. Change the ListView height attribute to wrap_content. Since the list content is small it couldn’t occupy the entire screen so the remaining space is filled with the device theam, setting the listview height attribute to wrap_content will wrap perfectly to the list content without occupying any extra space.
  2. If you insist to go with match_parent for listview height attribute then you can set android:overScrollFooter=”@null” this will remove the drawable in the ListView footer content.
  3. If this dint solve your problem then if you have any inflated custom row for this ListView set a background color to that view.

OUTPUT:

Applying Solution 1

Since i dint use any custom views or layout for this ListView row i am just changing the android:layout_height to “wrap_content” to attain this output.

Applying Solution 2

Things To Note:

Compare the solution 2 with 1. Since ListView’s height is left to match_parent the bottom most divider line is visible if you set it as wrap_content then you wont get the bottom most divider.

Hope this solves your problem 🙂