Android Horizontal Layout with text wrap functionality - java

I want to create an layout, in which I should be able to add views dynamically and it should expand horizontally in a flow.
Here are things that I've tried:
Flow-Layouts
Problem with flow-layouts is that when using multiple textviews, if textview having long text, it takes whole textview to next line, but I want it to wrap the text and only move rest of the text to new line.
Spannable Textviews
I want to assign individual id's to views because when it's clicked it should highlight and function accordingly but with spanning it's not possible.

Related

Show the last text on scrollview

I'm creating a calculator app. I want the scroll view to scroll as I add new elements (numbers and signs) but it doesn't scroll. Once the text reaches the end of the screen I'm unable to see new elements until I manually scroll.
Then
The remaining part of the text
Try to call scrollView.fullScroll(View.FOCUS_RIGHT) after every text update.

Change TextView Text Alignment for Individual Appends

I am trying to create an Android app where data is read and alignment differs if a certain string is contained in the data. The data is then appended onto a textview with a carriage return. Using append, is there any way for me to change the text alignment for individual line entries? Currently what I've been doing is this
if(returnedData.contains(myVar)) {
myTextView.setGravity(Gravity.END);
} else {
myTextView.setGravity(Gravity.START);
}
Obviously this does not work because it changes the alignment of every line with each new append. Thank you ahead of time for any help.
android:layout_gravity is used to align the text view with respect to the parent layout. android:gravity is used to align the text inside the text view.
put these lines in your xml
Further make sure that you are trying to align the text inside the textview to the right or do you want to move the text view itself to the right with respect to the parent layout, solution will differ with different scenario.
also you can take two different textview and align that textview rather than setting them on single textview.

Add value to arraylist from edittext inside recyclerview

I am working on a recylerview which contains several edit text and 2 textview beside each edit text. Initially I want empty edit text when activity is loaded, after that putting some values in 1 or more edit text randomly. I do not want to loose the value on scroll up or down. Please provide a solution for that if possible.

Android - TextView in a Custom ListView loses its content while scrolling

I have came across these type of questions a lot, But none of the answers solved my problem.
I am developing a mobile shopping application model. I have a custom ListView with an ImageView, and EditText(quantity), 2 Buttons for increasing and decreasing the quantity, 3 TextViews one for item Name and other two for prices and I am dynamically loading a number of Buttons for NetWeights based on the requirement through Java code and I am implementing it using CustomAdapter(Class) extending BaseAdapter and getView().
Problem 1:
When I use the condition if(convertView==null), setTag(holder) and getTag(), the dynamically loaded Buttons are getting duplicated and gets doubled in number.
Problem 2:
While scrolling the custom ListView I am loosing my data on 2 of the TextViews while the other TextView(name) is fine because in that TextView I don't Change data on runtime. On the other two TextViews(prices) I change the data on runtime using ButtonClicks(increase and decrease) where at that time when I scroll the two TextViews, it looses its content. Actually I had this same problem with the EditText(displaying quantity), I solved it using the TextWatcher by getting the value and passing it in an array and again setting it. I used the same technique (i.e) the TextWatcher for the TextViews But that did'nt Help. I also tried removing the TextWatcher and setting the text with the array and adding TextWatcher. Still I am loosing my content in those TextViews
Any Suggestions??????
Problem 1:
While using ViewHolder (setTag(), getTag()) we will be reusing the views.
For example: Let's say we have 10 listview items and the screen can display 3 items at a time. Lets say we add 2 buttons to list item 1. First time when we load the listview we will see two buttons. Lets say now we scroll down and come back to the list item 1 again, as we are reusing the views, we already have 2 buttons and if we have the code to add buttons using getTag() then 2 more buttons will be added. I think this may be causing the issue of button duplication. To add little more information, list item 1, list item 4, list item 7 and list item 10 will all use same view, as our screen in this example can display just 3 items.
Problem 2:
One idea is to store all these text values in the arrayList.
For example, lets assume we have one textView inside each list item that can be incremented/ decremented. Set textWatcher on this textView and whenever text changes add it to the arrrayList using 'position' as the index. Inside getView method when you do getTag() try to set the textView using previously stored text (that was stored inside the arrayList)if exists.

Move to specific position in TextFlow JavaFX

I'm having a TextFlow inside a StackPane which is inside a ScrollPane. I'm adding text with different colors to this TextFlow
Text txt = new Text(msg);
txt.setFill(Paint.valueOf(color));
txtFlow.getChildren().add(txt);
I want to scroll to a some specific point in the textflow.
e.g. First text that is in blue color.
I know I can get the text and check the color. But how can I scroll down to that specific position?
Can I achieve that sort of functionality through the TextFlow?
Simply I'm trying to build up a diff view in JavaFX. And want to travel through the diffs.
I would take a ListView and put some stackpanes or directly the texts in it.
Text content = new Text("Custom Text");
content.setFill(Color.valueOf(yourcolor));
ListView<Text> list = new ListView<Text>();
list.add(content);
Because...
there's a void scrollTo() where you can scroll to the item directly by the Text object or to the item by the index (int).
To get a transparent background on the listview you can use:
list.setStyle("-fx-background-color: transparent;");
I hope this helped you.
I'm sorry if I missunderstood your question.
Peace
Use one of the free styledtext-editors - they all are using ListView or VirtualView internally. See https://github.com/TomasMikula/RichTextFX/wiki/JavaFX-Controls-for-Code-Editing for examples

Categories

Resources