Giter VIP home page Giter VIP logo

Comments (17)

BraisGabin avatar BraisGabin commented on July 20, 2024

First you need to update your TableFixHeaders code. Then you can use this hack:

final TableFixHeaders tableFixHeaders = (TableFixHeaders) findViewById(R.id.table);
tableFixHeaders.setAdapter(new MyAdapter(this));
new Handler().postDelayed(new Runnable() {

    @Override
    public void run() {
        tableFixHeaders.scrollBy(Integer.MAX_VALUE, Integer.MAX_VALUE);
    }
}, 50);

Why this Hack? If tableFixHeaders does not complete the onLayout() task, scrollBy(x, y) won't work. If you find a better solution or improves the code please, let me know.

from tablefixheaders.

MariuszGSL avatar MariuszGSL commented on July 20, 2024

I have got it working - thank you.
Here is my code (called from within the Fragment):

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle args) {   

    mDbHelper = new DbAdapter(getActivity());
    mDbHelper.open(); 
    View rootView = inflater.inflate(R.layout.s_events_fragment, container, false);
    tableFixHeaders = (TableFixHeaders) rootView.findViewById(R.id.table);
    return rootView;   
}

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);       

    tableAdapter = new EventListAdapter(getActivity());   
    tableFixHeaders.setAdapter(tableAdapter);                      

    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            tableFixHeaders.scrollBy(0, Integer.MAX_VALUE);
        }
    }, 50);        
}

Note that I have set the first scrollBy value to zero, to prevent horizontal movement to the last column cell.

However, I have come across two issues:

  1. Trying to run the above code on tablet emulator, it would crash (the problem was due to the very slow emulator run). Increasing the delay from 50 to 500 fixed the issue. However, in real life situation this might not be possible.
  2. In landscape mode, I am displaying two fragments (side by side), each having its own tableFixHeaders table view. When turning the phone into portrait mode, it is refreshing both views through callbacks (on Detach/on Attach). Only the first table view should be displayed in its own layout fragment in portrait mode, however the second view is being automatically refreshed in the process, and this causes the code to crash on the following line of code:
            } else {
        scrollY = Math.min(scrollY, Math.max(0, sumArray(heights, firstRow + 1, rowCount - firstRow) + heights[0] - height)); 

in the new scrollBy method. This is because the heights=null for the second table view, which is no longer visible.
Would it be possible to alter the scrollBy code to prevent it from running if the heights or widths values are null ? This might also prevent it from crashing if the delay is too short ?

from tablefixheaders.

BraisGabin avatar BraisGabin commented on July 20, 2024

Obviously this is a bug. I'll fix it.

from tablefixheaders.

BraisGabin avatar BraisGabin commented on July 20, 2024

I avoid the NullPointerException. This weekend I will improve the code and you will not need the handler. I have the idea, but I have not time to implement it now.

from tablefixheaders.

MariuszGSL avatar MariuszGSL commented on July 20, 2024

Great !
I have developed a very nice, simple code to sort the columns in your TableFixHeaders view, by clicking on the column header (both ascending and descending, with visual indication, which column is sorted and how).
I will prepare an example and share it with you, to enhance the features offered by your library.
What would be the best way of providing you with this sample code ?

from tablefixheaders.

BraisGabin avatar BraisGabin commented on July 20, 2024

This is great!

The best way is via pull request. Thus github will say that this commit is yours. But if you prefere other way: paste the code in a issue, paste the patch... I will merge it.

You will add your own entry in the list of samples and implement a new Activity with your code, won't you?

from tablefixheaders.

MariuszGSL avatar MariuszGSL commented on July 20, 2024

Yes, I will prepare a new sample (#4) and will try to use github to submit it (haven't done it before through github - will need to do some reading how this pull request is done).

from tablefixheaders.

BraisGabin avatar BraisGabin commented on July 20, 2024

It's pretty easy. Mail me if you need some help.

from tablefixheaders.

MariuszGSL avatar MariuszGSL commented on July 20, 2024

OK. Will do.

from tablefixheaders.

MariuszGSL avatar MariuszGSL commented on July 20, 2024

Just to let you know, the quick fix #10 has fixed the issue with the scrollBy code crashing when turning the device from landscape to portrait view.
Looking forward to see your improved code.

from tablefixheaders.

BraisGabin avatar BraisGabin commented on July 20, 2024

The quick fix problems... I'll fix all this weekend.

from tablefixheaders.

MariuszGSL avatar MariuszGSL commented on July 20, 2024

I have tested it and the new code works perfectly well. Thank you !
I have replaced the old handler.postDelayed code with the following:

    new Runnable() {
        @Override
        public void run() {
            tableFixHeaders.scrollBy(0, Integer.MAX_VALUE);
        }
    };

and it works well also on very slow tablet emulator.

from tablefixheaders.

MariuszGSL avatar MariuszGSL commented on July 20, 2024

Edit: I had to change back to the handler code (with 0 delay) as the code in the comment above did not work:

    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            tableFixHeaders.scrollBy(0, Integer.MAX_VALUE);
        }
    }, 0);

Would you be able to comment why the Handler.postDelayed code is still necessary for the scroll to the last row to work ?

from tablefixheaders.

BraisGabin avatar BraisGabin commented on July 20, 2024

No, I'm not. It's really strange. Try this:

tableFixHeaders.setAdapter(tableAdapter);
tableFixHeaders.scrollBy(0, Integer.MAX_VALUE);

The Handler should not be needed at all. But it should also continue working...

from tablefixheaders.

MariuszGSL avatar MariuszGSL commented on July 20, 2024

Yes, this last code works:

tableFixHeaders.scrollBy(0, Integer.MAX_VALUE);

but not the other one with new runnable() ....

Thanks for suggesting the simple working solution.

from tablefixheaders.

BraisGabin avatar BraisGabin commented on July 20, 2024

hmm... Did you only write that?

    new Runnable() {
        @Override
        public void run() {
            tableFixHeaders.scrollBy(0, Integer.MAX_VALUE);
        }
    };

This only create a runnable and the GB remove it in the next iteration. You didn't say that anyone run the runnable. This was the issue.

from tablefixheaders.

MariuszGSL avatar MariuszGSL commented on July 20, 2024

Hello Brais,
I have promised a long time ago to create a small example to show how to implement the sorting of columns in your TableFixHeaders, by clicking on the column header. At the end, this proved to be difficult without having the actual database source linked to the TableFixHeaders view.
However, recently I have released my application on Google Play, which demonstrates how this column sorting is implemented, as well as showing several other features (search, filtering, auto-record scrolling, cell highlighting, etc.) developed using your excellent library.
if you wish to check it out, please use the following link:
https://play.google.com/store/apps/details?id=com.eliteherd.elitemobile
Kind regards,
Mariusz

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.