Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scrolling makes header customizations appear on lines #16

Closed
tsuharesu opened this issue May 27, 2013 · 2 comments
Closed

Scrolling makes header customizations appear on lines #16

tsuharesu opened this issue May 27, 2013 · 2 comments
Labels

Comments

@tsuharesu
Copy link

I don't know if there is a problem in my code, but when I scroll the table fast, some customizations that I did in my header (typeface, background ...) appear on some lines.

This is my code in getView, made using MatrixTable as example.

public View getView(int row, int column, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = new TextView(context);
            ((TextView) convertView).setGravity(Gravity.CENTER_VERTICAL);
            ((TextView) convertView).setPadding(5, 2, 0, 2);

        }
        ((TextView) convertView).setText(table[row + 1][column + 1].toString());

        if (row == -1) {
            ((TextView) convertView).setTypeface(Typeface.DEFAULT_BOLD);
        } else if (row % 2 == 0) {
            convertView.setBackgroundColor(context.getResources().getColor(
                    br.com.tsuharesu.gamedevstoryhelp.R.color.even_bgcolor));
        } else {
            convertView.setBackgroundColor(context.getResources().getColor(
                    br.com.tsuharesu.gamedevstoryhelp.R.color.odd_bgcolor));
        }

        return convertView;
    }

I think it's because of recycling, but I'm not really sure. Thanks!

@tsuharesu
Copy link
Author

Yes, it was because of Recycling. Now I managed to fix it using the getItemViewType and it is working. Sorry for this.

Sorry for this, but I didn't understand why override and use this method instead of just checking row num in the getView method.

@tsuharesu
Copy link
Author

And if anyone (like me) don't know why use getItemViewType, there's a explanation here:
http://stackoverflow.com/questions/5300962/getviewtypecount-and-getitemviewtype-methods-of-arrayadapter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant