0

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?

1 Answer 1

3

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

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

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

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

ListView lv = ... ;
lv.setDivider(getResources().getDrawable(R.layout.list_separator));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.