1

I have used a custom array adapter to populate my list view.The problem i face is that the separator is missing out in between the fourth and fifth list item.

Here's the code:

public class Clubs extends ListActivity{ private static class EfficientAdapter extends BaseAdapter { private LayoutInflater mInflater; private Bitmap mIcon1; private Bitmap mIcon2; public EfficientAdapter(Context context) { // Cache the LayoutInflate to avoid asking for a new one each time. mInflater = LayoutInflater.from(context); // Icons bound to the rows. mIcon1 = BitmapFactory.decodeResource(context.getResources(), R.drawable.yellow_offline); mIcon2 = BitmapFactory.decodeResource(context.getResources(), R.drawable.green_online); } /** * The number of items in the list is determined by the number of speeches * in our array. * * @see android.widget.ListAdapter#getCount() */ public int getCount() { return DATA.length; } /** * Since the data comes from an array, just returning the index is * sufficent to get at the data. If we were using a more complex data * structure, we would return whatever object represents one row in the * list. * * @see android.widget.ListAdapter#getItem(int) */ public Object getItem(int position) { return position; } /** * Use the array index as a unique id. * * @see android.widget.ListAdapter#getItemId(int) */ public long getItemId(int position) { return position; } /** * Make a view to hold each row. * * @see android.widget.ListAdapter#getView(int, android.view.View, * android.view.ViewGroup) */ public View getView(int position, View convertView, ViewGroup parent) { // A ViewHolder keeps references to children views to avoid unneccessary calls // to findViewById() on each row. ViewHolder holder; // When convertView is not null, we can reuse it directly, there is no need // to reinflate it. We only inflate a new View when the convertView supplied // by ListView is null. if (convertView == null) { convertView = mInflater.inflate(R.layout.people_list_item, null); // Creates a ViewHolder and store references to the two children views // we want to bind data to. holder = new ViewHolder(); holder.text = (TextView) convertView.findViewById(R.id.textpeople); holder.icon = (ImageView) convertView.findViewById(R.id.image); convertView.setTag(holder); } else { // Get the ViewHolder back to get fast access to the TextView // and the ImageView. holder = (ViewHolder) convertView.getTag(); } // Bind the data efficiently with the holder. holder.text.setText(DATA[position]); holder.icon.setImageBitmap((position & 1) == 1 ? mIcon1 : mIcon2); return convertView; } static class ViewHolder { TextView text; ImageView icon; } } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setListAdapter(new EfficientAdapter(this)); } private static final String[] DATA = { "Abbaye de Belloc", "Abbaye du Mont des Cats", "Abertam", "Abondance", "Ackawi", "Acorn", "Adelost", "Affidelice au Chablis", }; } 

Here's the xml:

<?xml version="1.0" encoding="utf-8"?> <LinearLayout android:id="@+id/widget31" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal" xmlns:android="http://schemas.android.com/apk/res/android" > <LinearLayout android:id="@+id/widget321" android:layout_width="479dip" android:layout_height="54dip" android:layout_marginTop="16dip" > <ImageView android:id="@+id/image" android:layout_width="24dip" android:layout_height="24dip" android:layout_marginLeft="14dip" android:layout_marginTop="5dip" android:src="@drawable/green_online"> </ImageView> <TextView android:id="@+id/textpeople" android:layout_marginLeft="10dip" android:textColor="#FFF5EE" android:layout_height="29dip" android:textSize="16sp" android:layout_width="400dip" android:layout_marginTop="7dip" > </TextView> </LinearLayout> </LinearLayout> 

Here is the screen shot listseparator

can someone tell me where i have gone wrong? Thanks

EDIT:
Solution:
Here's the code to be added to get it working

ListView lv=getListView(); lv.setDividerHeight(2); 
2
  • which device you are testing I faced similar issue in HTC tatoo and found that its only device specific Commented Feb 24, 2011 at 12:38
  • I am testing it in the emulator. Commented Feb 24, 2011 at 12:45

1 Answer 1

4

the easy way would be to call setDividerHeight(2) in your onCreate method. In the more complicated way, you need to make sure your resources are correctly put in layout-hdpi / layout because what's happening there is that the OS approximates 1dpi to 0dpi because the app runs in compatibility mode. Also check out your supports-screens attribute in your manifest (try setting everything to true)

Sign up to request clarification or add additional context in comments.

2 Comments

can you tell me where to exactly place the setDividerHeight() in full syntax.I tried putting it in the oncreate.It is throwing me compilation errors.
You can also try in xml as: android:dividerHeight="3dip"

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.