removeAllViews() not removing TableRow children in a TableLayout - java

Some background:
I am having an issue with one part of my program where I am building a 'edit database' view and then removing the rows again. The fields which the 'edit database' view will show are different each time it is shown. The edit database view is a tablelayout, and each row in the database is a row in the table layout. when the user exits the edit view, the view is supposed to be disposed or wiped of rows for the next time.
My issue, is no matter what I try, I can't get the rows in the tablelayout to delete. Here are the relevent pieces of code:
Get a handle on the tablelayout in the xml file
setContentView(R.layout.database_entry);
TableLayout editorLayout = (TableLayout)findViewById(R.id.DatabaseLayout);
the layout is passed to another class, where they are added to the layout like this:
//layout is the tablelayout from earler, passed into this function
TableRow row = new TableRow(contex);
row .setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
//stuff added to the row....
//...
//...
layout.addView(row);
When I attempt to wipe the Tablelayout, I run this code
TableLayout editorLayout = (TableLayout)findViewById(R.id.DatabaseLayout);
editorLayout.removeAllViews();
Whatever I do, the next time I hit the button to edit the code, it will show the previous rows, as well as the new rows added. They are not removed from the table. I get no error messages or any useful debugging information, it just isn't functioning.
I have struggled with this for a while. Tried dynamically creating the tablelayout(no xml file), tried deleting each row (or just ONE row) with it's index. I have used the Hierarchy Viewer to check to make sure everything is a child of that tablelayout (it is). If anyone has any insight, it would be much appreciated.

I was able to figure out the issue. First of all, the comment above was a little bit wrong, the mChildren array did not contain any pointers to the views I had deleted. They were nulled out, just as they should have been.
The reason why none of my rows were deleted is because right after I called removeAllViews() I switched content views setContentView(R.layout.main);. when I commented this line out, the remove children code worked as expected. I assume some android back-end optimization code decided that the removeAllViews() didn't need to be run, or updated somewhere in memory. And all the changes made while inside this function didn't apply.
I will be putting all of this code in a new activity (where it really belonged in the beginning). But I wanted to provide an explanation in case someone else is having the same issue.

After removing the row try setting the visibility to GONE and back to Visible again, This should fix the remove row glitch.

Related

Adding row to a ListGrid at a specified index Smart GWT

Currently I'm working on a listgrid which is editable and my requirement is to create a a new row every time a user selects a row and presses the "Create" Button. The new row needs to be added immediately below the selected row. I tried using the below method
ListGrid.getRecordList().addAt(ListGridRecord rec, Index index)
However I got the warning message
15:48:04.373:MUP3:WARN:Log:ResultSets are readonly. This operation (addAt) will be ignored.
I've searched the smartgwt showcase to look for ways to edit a grid , so that new row is added at a specified index, however I wasn't able to find anything suitable.
I got to know that ResultSets is getting created because I'm using the statement
ListGrid.fetchData() Is there any way to solve this issue? Any suggestion is highly appreciated!
Muchas Gracias.
Figured it out, quite a weird trick...but works for me...
what you need to do is use grid.setRecords(grid.getRecords()); just before grid.getRecordList().addAt(rec, index); I think doing this makes the ResultSet editable.

How to force RCP to reload the table content

I have this huge RCP enterprise CRM system I'm working on. Last year it was updated to RCP 4.5. Sadly I'm very bad with RCP because I never had to do with the frontend of it... So my question might seem a little bit strange.
Anyways, my problem is:
I have one table window where all the rows all filled up correctly with data. One column has a function, where I can double click on and one other window will open, where I can edit/remove/add data to it. The IDs of the added values are then showing in the main window's table column. (this is working correctly)
The problem: If I open this editor window, edit something (add new values or remove one or more), then click save and close this edit window (it's actually a new tab...) and then going back to this window after the editing, it will show me the state BEFORE the editing... (new values are not in the list, removed one are still on the list) The values are correctly stored or deleted in the DB, only the UI seems to stuck with the old state. I have to restart the GUI if I want to see the correct (and the actual) state.
My question: how can I force RCP to forget the old state for this tab/window and load the data everytime from DB? I tried many things in the saving method of this window (refresh, dispose of), but nothing seems to work...
Are you using a TableViewer or so?. using the tableViewer.setInput(...) again with new data + layout() may solve the problem, buit as #greg-449 said, we need for information on what kind of taale you are using to display your data and how you tell that table where is this data...

How to get and set scrollbar position of Java table at run time?

Currently with help of JAVA SWT (org.eclipse.swt.widgets.Table & org.eclipse.jface.viewers.TableViewer library), I have a table which is getting populated from DB. Idea is to refresh the table data while user is scroll down to check the tables row using scroll-bar and let the scroll bar position restore to same point where it was before refresh event. So that user never feel that some refresh event is working in background while he scroll down the data.
Is there any inbuilt method or library exist in jdk or in above eclipse package to get & set the position of scroll-bar dynamically?
I found a logic to get scroll bar position
ScrollBar vScroll = Table.getVerticalBar();
int valuetemp = vScroll.getSelection();
But after refreshing the table content, when scroll-bar moved to very fist entry after that if I use below code to restore the scroll-bar. Ideally it should work as per API but it didn't move my scroll-bar position to the previous value.
vScroll.setSelection(valuetemp);
I had a similar problem. I tried to keep the scrollbar at the newest table input.
I did not found a solution for the
ScrollBar.class
but the following code worked for me:
table.setTopIndex(table.getItemCount()-1);
I hope this helps :)

Oracle-adf selectOneChoice reset on treeTable scrolling

I'm facing problem with a selectOneChoice inside a TreeTable in clickToEdit mode.
When scrolling down and returning up, the value of the combo of the focused row is cleaned.
To replicate the issue, just navigate to the ADF demo :
clickToEditTreeTable
Expand all
Select the first row
Change the value of the Col2 to HeadPhone
With the focus still on first row, scroll down until the Fetching Data message appear
Scroll up back to the first row
The value of the Col2 is changed to Mouse
How can i avoid this ?
In my application i have noticed that the value change listener is fired the first time when changing the value, and a second time while scrolling the treeTable,setting it to null
This problem occurs ONLY with a treeTable in editingMode clickToEdit.
The standard table works fine.
My jdev is 11.1.2.1.0.
Thx in advance.
Since you are able to reproduce this issue in ADF demo itself its either an ADF bug or limitation.
I think thats a kind of a bug. You can try to file service request on it.
It seems that since you don't commit your changes (because you still stays on this row). On another fetch your changes ain't being saved and on refetch you getting old values.
As for workaround for this issue:
If your tree ain't too large, you can set iterator RangeSize to -1 to fetch all rows at once to avoid more rows fetching. However if you have a lot of rows, you'll have a perfomance issues.
You can try to set autosubmit property on this field to true, so it will save your data (and hopefully load) on comback (even if it don't, you can do it in your bean). May be you will also need to put there clientListener to submit data, when your control loses focus.
Don't use clickToEdit for this control or call it a feature (no submit - no changes) :)
Since i can't wait a fix, i have found a workaround to the problem.
The value is setted to null ( or false for the checkboxes ), when the element is renderized the second time on scrolling back, because the setter property of the bean and ( if present ) the value change of the selectOneChoice are invoked.
So i have setted a clientListener on the valueChange event that unlike the valueChangeListener is fired correctly, and a fake property as value.

scrolle to a table raw in a scrolle view at run time

In my Android project I'm using a table layout contained in a scroll view. When a product is selected from a spinner the table view must automatically scroll to the table raw showing the relevant product's details. Unfortunately I can't post any of my code work. I have a big problem in scrolling the view. So can someone help me with some helpful code.
Thank you.
I think one solution is to know the index in your list of the selected product. Then you'll have to measure the childs in your ScrollView. When you know the sizes of your children and the index of the child you want to scroll to you can use ScrollView.scrollTo(x, y)
the y will be something like this: index * heightOfChild.
This is ofc if your childs are of the same size. Otherwise youll have to measure each child separatly.
Edit:
scrollTo apparently "clamps the scrolling to the bounds of our child." Not sure what it means... But you could try scrollBy(x, y) the documentation doesnt write anything about clamps for that.
if you are using a listView you could try setSelection() as described here:
Android scroll to the bottom of a listview

Categories