How to make TextView have maxLines and if it doesn't fit expand horizontally? - android-layout

I don't want to use scrollView.The behavior I want is this:
Short Text:
Long text:

Have you tried minLines in XML?
something like this:
<TextView
android:id="#+id/tv_previous_story"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:minLines="2" //(could be any minimum amount of lines)
android:textColor="#color/text_color"
android:textSize="#dimen/privacy_text_size" />
this should work fine for you if you always have at least two words (or the minimal amount of lines you've set in the XML)...
If this isn't what you search for, maybe you could handle it programmatically and set the width and height of the TextView according to the number of words... not the exact method, but for example:
void updateWidthAndHeightOfTextView(TextView tv, String t) {
tv.setWidth(t.length * [bla bla bla]);
tv.setHeight(tv.getWidth() / [bla bla bla]); //(if you want to change the height too, in this case according to the width)
}
You write it your way, you know your needs...
And, there's also this answer, that I'm actually not familiar with but might also answer your needs...
UPDATE
In case I didn't understand when I wrote the above and you want the TextView to have maxLines and only dynamic width, you could use the tv.setWidth(t.length * [bla bla bla]); in the semi method that I wrote above, and in the .XML use maxLines...
Also, next time please give a bit more specific questions so people won't have to struggle to try to understand how to give you the relevant answer to what you want.
I hope it helps you!

Try this:
<TextView
android:layout_width="wrap_content"
android:layout_height="100dp"
android:text="Your text here"
android:textColor="#color/purple_500"
android:textStyle="bold"
android:lines="2"
android:gravity="center"
android:autoSizeTextType="uniform"
android:autoSizeMinTextSize="16sp"
android:autoSizeMaxTextSize="100sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
For short text your output be like:
For long text:

Related

How to ignore unnecessary input of Zeros (0) and dot (.) in a calculator app using kotlin/android studio [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 days ago.
Improve this question
1--> Ive been trying to make a calculator app. My problem is that I want my app to ignore unnecessary repeating input by the user to avoid having this kind of repeating zeros(0) and dot(.) : 00000.003, 3..03, 3+00000.003, etc
I'm new here so I don't know what else I could experiment on.
I've tried a combination of while loop with nested ifs with some conditions like text.startsWith, .endsWith("str", ignorecase: false) something like that for my onclick buttons.
Some code suggestions is highly appreciated.
2-->Also i've been thinking if there's a series of command/code where an individual textview will be created every time characters(created by onclick buttons) formed an integer/expression/decimalnumber(etc) as well as operation(+,-,*,/)
in a way that every number and math operations are separated into textviews(for editing purposes)
I hope someone can give me an idea and codes/commands that I might try to experiment with to develop my app
<EditText
android:id="#+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number" />
or
In this sample code, the text in the EditText is first converted to an Int value. If the conversion fails (that is, there is no numeric value in the text box), 0 is set by default. Next, the EditText's text is replaced with the numeric value with the redundant 0's removed.
val editText: EditText = findViewById(R.id.editText)
val number: Int = editText.text.toString().toIntOrNull() ?: 0
editText.setText(number.toString())
allows only text values ​​to be entered
val editText: EditText = findViewById(R.id.editText)
editText.filters = arrayOf(InputFilter { source, _, _, _, _, _ ->
if (source.toString().matches(Regex("[0-9]+"))) {
source
} else {
""
}
})

JMeter: # notation (for xml)

On groovy templates for jmeter page there is an example I wanted to follow:
String xml = “
<actions>
<action type=”error” info=”itsErrors”/>
<action type="warning" info=”warnWarn”/>
<action type=”info” info=”justLogInfo”/>
</actions>"
XmlParser parser = new XmlParser()
def actions= parser.parseText (xml)
actions.action.each { action ->
println "${action.'#type'}: ${action.'#info'}";
}
At least in my JMeter 5.1 it did not work as posted, but when I fixed quotation marks it did:
String xml = """
<actions>
<action type="error" info="itsErrors"/>
<action type="warning" info="warnWarn"/>
<action type="info" info="justLogInfo"/>
</actions>"""
XmlParser parser = new XmlParser()
def actions= parser.parseText (xml)
actions.action.each { action ->
println "${action.'#type'}: ${action.'#info'}";
}
My question is usage of # mainly, dot and quotes too (.'#type'). I tried web search for Groovy # and found nothing, for JMeter notations found https://jmeter.apache.org/usermanual/functions.html with only one instance of usage:
Example: ${__XPath(/path/to/build.xml, //target/#name)} This will
match all targets in build.xml and return the contents of the next
name attribute
And about variables same link:
Referencing a variable in a test element is done by bracketing the
variable name with '${' and '}'.
Groovy docs page for xml gives other notations:
https://groovy-lang.org/processing-xml.html
def text = '''
<list>
<technology>
<name>Groovy</name>
</technology>
</list>
'''
def list = new XmlParser().parseText(text)
assert list instanceof groovy.util.Node
assert list.technology.name.text() == 'Groovy'
What each notation in "${action.'#type'}: ${action.'#info'}" means?
It isn't a JMeter variable even with ${}, is it?
I managed to keep in working only w/put ', other parts seems necessary: ", ., #, {}, $. I may have put extra in last phrase, some I can explain, but just to be sure I understand it right.
It's GPath syntax used in groovy
The most common way of querying XML in Groovy is using GPath
For XML, you can also specify attributes, e.g.:
a["#href"] → the href attribute of all the a elements
a.'#href' → an alternative way of expressing this
a.#href → an alternative way of expressing this when using XmlSlurper

i am having problem to add comma with space in data-binding XML layout in android

Databinding is the most commonly used to bind UI views in layout to data source. that is why I decided to use this approach.
Actually, I am to concatenate to of the values from data source and to be shown in view. concatenation is not a big deal I just added "+" operator between the values or variables of the data source.
The problem is how to add space between two of them.
concatenating two of the values by "+" operator was working fine.
<TextView
android:id="#+id/location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="#sample/title"
android:text="#{item.location.get(0).getlocation_text + item.location.get(0).city}"
android:maxLines="2"
android:ellipsize="end"
android:gravity="start"
android:textAppearance="#style/TextDesc2"
card_view:layout_constraintTop_toBottomOf="#+id/title"
card_view:layout_constraintStart_toStartOf="parent"
card_view:layout_constraintEnd_toEndOf="parent"
android:layout_marginTop="8dp" card_view:layout_constraintHorizontal_bias="0.0"/>
I need the result as "locatin_text, city"
but now I am getting "location_textcity"
You can use double quotes with back quotes or single quotes with double quotes. Check this Android developer document reference.
1st way
android:text="#{item.location.get(0).getlocation_text + `, ` + item.location.get(0).city}"
2nd way
android:text='#{item.location.get(0).getlocation_text + ", " + item.location.get(0).city}'
try this
android:text='#{String.format("%s %s", item.location.get(0).getlocation_text, item.location.get(0).city)}'

Limit the size of the textview horizontally

I have this text view
<TextView android:id="#+id/name"
android:singleLine="true"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:textSize="16sp"
android:layout_width="fill_parent"/>
The problem is if the text is bigger then the textview can display it just stop displaying it looks something like this |some unfinished tex| I want to have dots on the end in this way it will be more clear to the user that this is unfinished and it it is displayed only a part of the text
I would prefer something like this |Some unfinished te..|
How to implement this ?
Have you tried setting android:ellipsize paremeter to "end"?
I used the hack by checking text size every time i set it to textview and appended those dots after a substring of text.I don't know it is bad practice or so!! :P
you can do this type;
public String getChar(String inputstring){
String substring;
if(inputstring.length() >0 ){
substring=inputstring.substring(int beginIndex, int endIndex);
}
StringBuilder sb=new StringBuilder(substring);
sb.append("....");
return sb.tostring();
}

Sharepoint XSLT Dynamic filtering

I'm trying to create a dynamic row filter based on a variable. I have the following code:
<xsl:variable name="filter" select="contain(#Title, 'title1') or contain(#Title, 'title2')"/>
<xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row[string($filter)]" />
This unfortunately doesn't seem to work and I end up with all rows. I'm guessing the filter doesn't actually get applied, since I can copy and paste the output of the $filter variable, copy and paste it in the Row[] and it works as expected.
Anyone tried to do this before?
In case you're wondering the filter variable is actually created using a template that splits a string like:
title1 - title2 - title3
and returns a string like:
contain(#Title, 'title1') or contain(#Title, 'title2') or contain(#Title, 'title3')
Any help would be greatly appreciated!
You can't do what you seem to be attempting here. An XPath expression is atomical, you can't save parts of it and re-use them (apart from that it is contains(), not contain()).
You need something like this:
<xsl:variable name="Rows" select="
/dsQueryResponse/Rows/Row[
contains(#Title, 'title1') or contains(#Title, 'title2')
]
" />
Your "filter" does not work because if $filter is a string, then it is a string, nothing else. It does not get a magical meaning just because it looks like XPath. ;-)
This
<xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row[string($filter)]" />
evaluates to a non-empty string as the predicate. And any non-empty string evaluates to true, which makes the expression return every node there is.
If you want a dynamic filter based on an input string, then do this:
<xsl:variable name="filter" select="'|title1|title2|title3|'" />
<xsl:variable name="Rows" select="
/dsQueryResponse/Rows/Row[
contains(
$filter,
concat('|', #Title, '|')
)
]
" />
The use of delimiters also prevents "title11" from showing up if you look for "title1".
Make sure your filter always starts and ends with a delimiter, and use a delimiter that is reasonably unlikely to ever occur as a natural part of #Title. (For example, you could use 
. If your title cannot be multi-line this is pretty safe.)

Resources