Android的ListView的分离器 [英] Android listview separator

查看:165
本文介绍了Android的ListView的分离器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要显示在列表视图我一个非常简单的分隔符。我做了一个扩展SimpleAdapter自定义适配器,我的工作的实施有点。它显示了分频器和我的名单正确的,但一旦我开始滚动,然后滚动备份分频器被搞砸了,放在代替时listItems等有时当我滚动多一些它看起来正确的一次。这是我的code为'getView

I want to display a very simple separator in my listview. I have made a custom adapter that extends 'SimpleAdapter' and my implementation works somewhat. It displays the dividers and my list correct but once I start to scroll and then scroll back up the dividers gets messed up, placed instead of listitems etc. Sometime when I scroll some more it will look correct again. This is my code for 'getView'

@Override
    public View getView(int position, View convertView, ViewGroup parent){
            if(((String)items.get(position).get("name")).startsWith("-")){
                View divider = inflater.inflate(R.layout.list_separator, null);
                TextView separator = (TextView)divider.findViewById(R.id.separator);
                separator.setText(((String)items.get(position).get("name")));

                return divider;
            } else {
                return super.getView(position, convertView, parent);
            }
    }

什么可能是我的问题?

What might be my problem?

推荐答案

如果您的分隔符是很简单的,你说,你有两个更好的方法来把它的列表视图:

If your separator is very simple as you say, you have two better ways to put it in the listview:

采用了android 1.Put它在XML:分属性:

1.Put it in the xml using android:divider attribute:

<item name="android:divider">@layout/list_separator</item>

2.使用方法<一个href=\"http://developer.android.com/reference/android/widget/ListView.html#setDivider%28android.graphics.drawable.Drawable%29\"相对=nofollow> setDivider()从ListView控件,给你的布局绘制对象:

2.Use the method setDivider() from ListView, give your layout as Drawable.:

ListView lv = ... ;
lv.setDivider(getResources().getDrawable(R.layout.list_separator));

这篇关于Android的ListView的分离器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆