我已經使用自定義數組適配器來填充我的列表視圖。我面臨的問題是分隔符在第四個和第五個列表項之間缺失。Android中的列表項之間缺少分隔符
下面的代碼:
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",
};
}
這裏的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>
下面是屏幕截圖
有人可以告訴我在哪裏出了問題? 感謝
編輯:
解決方案:
下面的代碼添加到搞不定
ListView lv=getListView();
lv.setDividerHeight(2);
你正在測試哪個設備我在HTC tatoo遇到類似的問題,並發現它的唯一設備專用 – ingsaurabh 2011-02-24 12:38:59
我正在模擬器中測試它。 – rogerstone 2011-02-24 12:45:18