Giter VIP home page Giter VIP logo

Comments (8)

BraisGabin avatar BraisGabin commented on June 22, 2024

I have a nexus 7 with 4.3 too. I will try to reproduce the bug this weekend.

Can you post your Adapter?

from tablefixheaders.

darkesfang avatar darkesfang commented on June 22, 2024

Love to!
The data scale is about 20*100 in general.
Thanks. :)


public class MyAdapter extends BaseTableAdapter {

    private final float density;

    public MyAdapter(Context context) {
        density = context.getResources().getDisplayMetrics().density;
    }

    @Override
    public int getRowCount() {
        // Row number without fixed part
        return mData.rowCount;
    }

    @Override
    public int getColumnCount() {
        // Column number without fixed part
        return mData.displayTable.size() - 2;
    }

    @Override
    public View getView(int row, int column, View convertView, ViewGroup parent) {

        View view;
        switch (getItemViewType(row, column)) {
            case 0:
                view = getFirstHeader(row, column, convertView, parent);
                break;
            case 1:
                view = getHeader(row, column, convertView, parent);
                break;
            case 2:
                view = getFirstBody(row, column, convertView, parent);
                break;
            case 3:
                view = getBody(row, column, convertView, parent);
                break;
            default:
                throw new RuntimeException("wtf?");
        }
        return view;
    }

    @Override
    public int getWidth(int column) {
        return Math.round(mData.displayTable.get(column + 1).width * density);
    }

    @Override
    public int getHeight(int row) {
        final int height;
        if (row == -1) {
            height = 90;
        } else {
            height = 55;
        }
        return Math.round(height * density);
    }

    @Override
    public int getItemViewType(int row, int column) {
        final int itemViewType;
        if (row == -1 && column == -1) {
            itemViewType = 0;
        } else if (row == -1) {
            itemViewType = 1;
        } else if (column == -1) {
            itemViewType = 2;
        } else {
            itemViewType = 3;
        }
        return itemViewType;
    }

    @Override
    public int getViewTypeCount() {
        return 4;
    }

    private View getFirstHeader(int row, int column, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = getActivity().getLayoutInflater().inflate(R.layout.item_table_header_first, parent, false);
        }

        ((TextView) convertView.findViewById(android.R.id.text1)).setText(mData.displayTable.get(0).header);
        ((TextView) convertView.findViewById(android.R.id.text2)).setText(mData.displayTable.get(1).header);
        return convertView;
    }

    private View getHeader(int row, int column, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = getActivity().getLayoutInflater().inflate(R.layout.item_table_header, parent, false);
        }
        // Start from the third column
        ((TextView) convertView.findViewById(android.R.id.text1)).setText(mData.displayTable.get(column + 2).header);
        return convertView;
    }

    private View getFirstBody(int row, int column, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = getActivity().getLayoutInflater().inflate(R.layout.item_table_first, parent, false);
        }
        convertView.setBackgroundResource((row + 1) % 5 == 0 ? R.drawable.bg_table_highlight : R.drawable.bg_table_normal);
        ((TextView) convertView.findViewById(android.R.id.text1)).setText(mData.displayTable.get(0).textData.get(row));
        ((TextView) convertView.findViewById(android.R.id.text2)).setText(mData.displayTable.get(1).textData.get(row));
        return convertView;
    }

    private View getBody(int row, int column, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = getActivity().getLayoutInflater().inflate(R.layout.item_table, parent, false);
        }
        convertView.setBackgroundResource((row + 1) % 5 == 0 ? R.drawable.bg_table_highlight : R.drawable.bg_table_normal);
        // Start from the third column
        ((TextView) convertView.findViewById(android.R.id.text1)).setText(mData.displayTable.get(column + 2).textData.get(row));
        return convertView;
    }
}

from tablefixheaders.

BraisGabin avatar BraisGabin commented on June 22, 2024

It isn't an error with 4.3 or Nexus 7. The adapter or the data must have an error but I can't find it.

This error has me quite curious. If you share a simple example which reproduces the error I will debug it. You can upload the code to GitHub, for example.

from tablefixheaders.

darkesfang avatar darkesfang commented on June 22, 2024

The data source is quite complicate, I'll try to reproduce the error with simpler case.

I'm curious too, how can this error not happening on other device..

from tablefixheaders.

darkesfang avatar darkesfang commented on June 22, 2024

Hi, sorry for late reply, I've been very busy lately. :(

I tried running my project on every android device I can get, they all work fine, except for Nexus 7 with Android 4.3.
I upload a test project on here (can't create new repo on GitHub, weird), which can reproduce the problem on my Nexus.

I'm new to this, so please let me know if there's something wrong with the project.
Hope this helps!

from tablefixheaders.

BraisGabin avatar BraisGabin commented on June 22, 2024

Really strange bug. You can check it with this change: https://github.com/BraisGabin/TableTest/commit/e41470b126c4c2c74811873109e84e9f16df76ba

The TextView.getText() log the correct value but display another. It seems an Android 4.3 bug but I'm not sure.

If you simplify the layout the issue disappears. For example: https://github.com/BraisGabin/TableTest/commit/655774c6bb5bad661d99eacd7f6a0ed6781d2ef8

from tablefixheaders.

darkesfang avatar darkesfang commented on June 22, 2024

Simplify the layout solving my problem, thank you very much!!!
Still it's a strange bug..

from tablefixheaders.

nylqd avatar nylqd commented on June 22, 2024

Hi there, may be you should check this out.

use

convertView = getLayoutInflater().inflate(R.layout.item_table, parent, false);

instead

if (convertView == null)
{
       convertView = getLayoutInflater().inflate(R.layout.item_table, parent, false);
}

this may sacrifice performance, but it seems can fix it.

from tablefixheaders.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.