I have an object on my main.xml layout file called thefact that is TextView. I also have a string called sharefact. I want to save what text is in the TextView into the sharefact string. I can't do:
sharefact = thefact
Or anything similar to that because it would want me to convert sharefact into a textview.
Thanks!
GetText returns the text from the single-line text field. It returns only the first line of a multi-line text field.
To use preset sizes to set up the autosizing of TextView programmatically, call the setAutoSizeTextTypeUniformWithPresetSizes(int[] presetSizes, int unit) method. Provide an array of sizes and any TypedValue dimension unit for the size.
SetText(String, TextView+BufferType)Sets the text to be displayed using a string resource identifier.
EditText is used for user input. TextView is used to display text and is not editable by the user. TextView can be updated programatically at any time.
TextView theFact = (TextView) findViewById(R.id.theFact);
String shareFact = theFact.getText().toString();
Getting text from a TextView
returns CharSequence
. To convert CharSequence
to String
, toString()
function is used.
String sharedFact = theFact.getText().toString();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With