How to draw vertical line between RecyclerView elements and also within element? - java

Here is screenshot
You can see on the screenshot RecyclerView with a different type of the elements.
Question is: How to connect consistently each element by vertical line (as you can see on the right side of the screenshot)?
Also there is a question about the vertical line that consist within one of the RecyclerView element (as you can see on the screenshot). Height of the line should be able to dynamically change according of the number of elements that it lead(you can see blue line and bullets on it).
Fell free to ask
Appreciate any kind of ideas

You can use ItemDecorator
1) Override method onDraw(...)
2) find interested views via recycler.getChildAt()
3) if you need view holder to check type, you can get it via getChildViewHolder
4) draw vertical line within bounds of view

Related

How to change item position of RecyclerView before the 0 element in my ArrayList

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 !

show array in single line in debug view in eclipse

Arrays in my debug view in eclipse are shown element-by-element downwards. This makes it difficult visually if I have too many arrays since I have to keep scrolling and cannot see all of them on a single screen.
Is there a way to see the array in a single line in the Variables section of the debug view in Eclipse?
You can use the below snippet to print in one line.
java.util.Arrays.toString(theArray);
There's no way (that I know of) of showing the array in a single line in the Variables View. I don't have eclipse installed in this PC but, as Kulbhushan said, you can try to execute the code
java.util.Arrays.toString(array);
in the Display View (to open it go to Window > Show View > Display).

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

Make Label Displayed Inside a Vertex Box (jgraphx library)

I need my vertex label displayed entirely inside vertex bounds. I mean if my label is too long then part of it will be displayed outside the vertex box. Is there any way to automatically split label into multiple lines and make it fit the vertex bounds? This line breaks should be recalculated after vertex resize. Can i do it using styles? mxUtils.wordWrap() seems to be the way but i cannot figure out how to use it properly. Give me an example of using it please. Thanks for your answers
Another similar question: Calculate the display width of a string in Java
Abstract:
Graphics.getFontMetrics + FontMetrics.stringWidth
From this, I suppose you could create a List<String> and add the words of the text one at a time until you reach your max length, then add a new node to the list for the overflow. Finally, append each node in the List to each other with a line break in between.
On another note, from what research I did, it seems jGraphX runs on swing. Swing now supports HTML. Here's a link to further info: http://docs.oracle.com/javase/tutorial/uiswing/components/html.html.
I will see if I can get a quick test coded up, but that must wait until I get home.

Why does adding this empty padding View mess up my layout?

So I'm using layout weights to scale parts of my layout to a certain fraction of the screen, and when I try to add an empty view for padding between elements, it causes a 0-size error on the views.
The original layout, which works before adding anything is:
http://pastiebin.com/?page=p&id=4e9777a2639f4 (Sorry for the pastebins instead of pasting it here, it wouldn't format correctly because of the xml tags)
And adding this between, or before or after any of the DWIButtons cause the error:
http://pastiebin.com/?page=p&id=4e9777caefc2d
I have no idea what to do here ):
EDIT 1:
Here it is without the padding view added
EDIT 2:
Also, adding any other type of view doesn't mess it up. I added a TextView instead of a blank View, and it resized correctly
adding images might help us understand the situation. but i suspect the layout weight is what is messing up your layout. setting layout weight to 1 means you want the blank layout to fill the available space(most of the time the entire screen).

Categories