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
Related
This question already has an answer here:
RecyclerView with StaggeredGridLayoutManager : variable number of columns and vertically scrollable
(1 answer)
Closed 10 months ago.
I need to make panel of some sort with a Staggered Grid behavior such in the photo attached (cells width are not the same in each cell):
I tried normal GridView, I tried StaggeredGridLayoutManager with and without a recycler view,
I've searched the internet for so long, and still hasn't found anything that gave me the suitable solution in java.
I also tried with the following answer: LayoutManager for RecyclerView Grid with different cell width and Android Grid view with different width of column (There are many more answers similar to this 2), but I need it to be "dynamic" and what I mean by that is that I need the cell width to be determine by it's content width and not just by it's index like in the answers attached.
Anyone knows a way to accomplish such a thing? or knows a library or a similar project with that feature?
p.s: if there is anything else you need me to add to this question in order to clarify, comment it please :)
It looks like https://github.com/google/flexbox-layout may help you.
You can use FlexboxLayoutManager as adapter and play with properties, all the views will wrap automatically depending on their width.
I have a RecyclerView with a cell row that have a favorite button. I was searching on SO and found a question with the same thing that I want to do here : implementing "add to favourite" mechanism in RecyclerView
the problem is that is not clear for me for now.
I dont want to have 2 recyclerViews and delegate the view to the other one because I will need to have 2 onCreateViewHolders and will be really unconfortable to work with, also bad coded.
What I need to do is like a row and then move it to the top with the title Favorite on it.
What comes to my mind is just delete the item im clicking and moving it to the 0 position of my ArrayList<Object> , but if I move that element to the 0 position it will overwrite my current element in the 0 position. Instead, I need to create a transparent row cell that says for example Favorites, and then below that cell (assuming is before 0 position in my array) start adding the favorites below it.
I will illustrate what I need to do.
This image is in the same RecyclerView without creating a new one above to show favorites. What I need to do is clicking one element, removing it and just replace it at the top of the RecyclerView but with a text on the top that says favorites, and after that each element that I add to the favorite list is just placed below the latest one there, so I was wondering what is the best way to accomplish this behaviour
This is what I need, pressing to like below, and then have my liked rows above, all in one place.
Thanks for any hint !
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 :)
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.
Hey,.. i wanna show pictures with names onit in a jList, i know it get's also in a JPanel but i'm now using a jList, doesn't matter..
My question is why does the jlist don't fit the images only in 2 horizontal 'cells' and then go one row down?
sry my english is bad and i don't know how to describe it better, but look on the picture, why does the jlist dont set the e.g. 3rd picture right next to the 2nd?
JList.HORIZONTAL_WRAP works correctly in the ListDialog JWS demo, as described in Initializing a List. I suspect a layout problem, but you might compare your code to the examples found there.
If you use HORIZONTAL_WRAP you can adjust the number of columns with setVisibleRowCount. If you want them automatically fitted to the width of the list, use 0 or something negative.