Giter VIP home page Giter VIP logo

Comments (14)

ashx1 avatar ashx1 commented on July 20, 2024

You can get the X and Y position of the table using these two methods:

tableFixHeaders.getActualScrollX();
tableFixHeaders.getActualScrollY();

Before you start your other activity, get the Y position of the table so you can do something like this:

TableFixHeaders tableFixHeaders = (TableFixHeaders) findViewById(R.id.table);
int x = tableFixHeaders.getActualScrollX();
int y = tableFixHeaders.getActualScrollY();

And when you return back to your activity:
TableFixHeaders tableFixHeaders = (TableFixHeaders) findViewById(R.id.table);
tableFixHeaders.scrollTo(x, y);

from tablefixheaders.

BraisGabin avatar BraisGabin commented on July 20, 2024

The @ashx1's comment is completely right. However, can't you archive this without setting a new adapter? You can refresh the adapter data and call notifyDataSetChangued().

from tablefixheaders.

MariuszGSL avatar MariuszGSL commented on July 20, 2024

Thank you for your suggestion, but it only partially solves the problem.
The tableFixHeaders.getActualScrollY() is only executed (i.e. set different from 0) when the table is actually scrolled down, to reveal new rows. It does not work when the selected row is just touched (without scrolling).
I need to know the precise position of the touched row, not the amount of actual vertical scroll offset, because I need to return to the same row position in the originally touched parent table. This should then activate another activity, based on that specific (return) row position.
Please think about a classic parent > child table relationship: a click on a row in the parent table selects a different set of records in the child table grid - this is precisely how I am using the tableFixHeaders.

Is there another call to the tableFixHeaders library that will give me the vertical (Y) position of the touched row ?
Or preferably, the touched row number ?

from tablefixheaders.

ashx1 avatar ashx1 commented on July 20, 2024

There is tableFixHeaders.getY(); : which is The visual y position of this view, in pixels. This is equivalent to the translationY property plus the current top property.

Maybe you could set the row number as a tag on the row, and then when your row is clicked you can get the tag of the row which means you will get the row number of the touched row?

from tablefixheaders.

MariuszGSL avatar MariuszGSL commented on July 20, 2024

Re. Refreshing the adapter data:
I am using lifecycle Callbacks functions to move between activities and fragments. This works perfectly well when pressing back button to return to the parent table grid, which is preserved and in exactly the same position as left before (no need to adjust any scrolling).
However, some other activities can change the data values in the parent table grid and the cell colour of the previously touched parent table row (the edited and saved data rows are marked with a different cell colour).

Currently I use the following code to reset the master grid table after each data / colour change:
SowListF.tableAdapter = null;
SowListF.tableAdapter = new SowListAdapter(this);
SowListF.tableFixHeaders.setAdapter(SowListF.tableAdapter);
SowListF.tableFixHeaders.scrollBy(0, SowListA.LastRowPosition);

The above code forces the SQLite query to extract a new (modified) set of table data, which is then displayed by setting up a new adapter.

Is it possible to refresh the original tableFixHeaders table grid adapter to display the new cell values and cell colour, without setting up the new adapter (as above) ?

How do I make those refresh adapter calls and use it with the notifyDataSetChangued() call ?

from tablefixheaders.

ashx1 avatar ashx1 commented on July 20, 2024

I am not to sure on how to refresh the adapter calls and use it with notifyDataSetChanged, @BraisGabin would be the best person to answer that.

from tablefixheaders.

MariuszGSL avatar MariuszGSL commented on July 20, 2024

I cannot find the method tableFixHeaders.getY() ?
There is public method onInterceptTouchEvent which obtains currentY in MotionEvent.ACTION_DOWN, however the currentY is a private (internal) variable, not accessible from outside the library.
There is a public method ScrollTo inside tableFixHeaders (which overrides ScrollTo in View) but I don't know where/how it is called and how to provide the necessary Y value to relayout the table grid.

from tablefixheaders.

BraisGabin avatar BraisGabin commented on July 20, 2024
SowListF.tableAdapter.forceSQLiteQuery(); // you must implement this
SowListF.tableAdapter.notifyDataSetChangued();

This should work. Although writing forceSQLiteQuery () can be more or
less difficult depending on your adapter implementation.

from tablefixheaders.

ashx1 avatar ashx1 commented on July 20, 2024

As @BraisGabin has probably answered your question above. Just on your last comment where you could not find the method tableFixHeaders.getY(), it is there as this is a method in the class View. ViewGroup extends View and TableFixHeaders extends ViewGroup:

http://developer.android.com/reference/android/view/View.html#getX%28%29

from tablefixheaders.

MariuszGSL avatar MariuszGSL commented on July 20, 2024

I have got it to work to have the previously touched row to stay visible within the displayed table section, after setting a new adapter to update the table contents. I have implemented it as previously suggested using:
tableFixHeaders.getActualScrollY();
and
tableFixHeaders.scrollTo(0, y);

However, I am having problem with implementing the suggested adapter refresh using the call to:
notifyDataSetChanged(), instead of setting the new adapter each time the table contents gets changed.
I am using the library calls to your TableAdapter, (as per your examples). This library does not include the notifyDataSetChanged() method.
That method is only available in the BaseTableAdapter part of your library, which I am not able to call directly.

Would you be able to suggest how to implement this call to the notifyDataSetChanged(), to gain access to this method. A small example code would be very helpful and highly appreciated.
Many thanks.

from tablefixheaders.

BraisGabin avatar BraisGabin commented on July 20, 2024

One possible implementation: https://github.com/InQBarna/TableFixHeaders/blob/master/library/src/com/inqbarna/tablefixheaders/adapters/BaseTableAdapter.java

from tablefixheaders.

MariuszGSL avatar MariuszGSL commented on July 20, 2024

I have added the method:
@OverRide
public void notifyDataSetChanged() {
mDataSetObservable.notifyChanged();
}
to my application TableAdpater which extends the BaseTableAdpater,
however, I am getting an error message: "The field BaseTableAdpater.mDataSetObesrvable is not visible"

I noticed that in your library, the BaseTableAdapter implements TableAdapter, which includes the above method.

How to overcome this issue and how to call this method directly from my TableAdapter ?

from tablefixheaders.

ashx1 avatar ashx1 commented on July 20, 2024

Maybe instead of mDataSetObservable.notifyChanged(); try super.notifyDataSetChanged();

The super.notifyDataSetChanged(); should call the class method that this class has inherited/implemented from.

from tablefixheaders.

MariuszGSL avatar MariuszGSL commented on July 20, 2024

Thank you. That seems to have done the trick.
I now have to develop the second part of the refresh procedure:
SowListF.tableAdapter.forceSQLiteQuery();
as suggested by @BraisGabin.
I will let you know if I have succeeded.

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.