highlight listview items android

Posted by user1752939 on Stack Overflow See other posts from Stack Overflow or by user1752939
Published on 2012-10-30T10:53:31Z Indexed on 2012/10/30 11:01 UTC
Read the original article Hit count: 154

Filed under:
|
|

I have listview with custom base adapter. When I populate the list I have to check a boolean in the object I'm populating the listview and if it is true to change the background color of that row.

public View getView(int position, View convertView, ViewGroup parent) {
    LoginsList entry = listOfLoginsLists.get(position);
    if (convertView == null) {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.lists_row, null);
    }

    TextView ListName = (TextView) convertView.findViewById(R.id.tvListName);
    ListName.setText(entry.getListName());

    TextView ListDescription = (TextView) convertView.findViewById(R.id.tvListDescription);
    ListDescription.setText(entry.getListDescription());

    Button Send = (Button) convertView.findViewById(R.id.bSend);
    Send.setOnClickListener(this);
    Send.setTag(entry);

    RelativeLayout RelLayout = (RelativeLayout) convertView.findViewById(R.id.layoutListsRow);
    RelLayout.setFocusableInTouchMode(false);
    RelLayout.setFocusable(false);
    RelLayout.setOnClickListener(this);
    RelLayout.setTag(entry);

    if (entry.isSent()) {
        RelLayout.setBackgroundColor(Color.parseColor("#4400FF00"));
    }

    return convertView;
}

But this code doesn't work right. When I scroll the list view the rows colors get messed up.

© Stack Overflow or respective owner

Related posts about android

Related posts about listview