I would like to create an android widget with a scrollable textview.
The solutions given to this question
Making TextView scrollable on Android
cannot be applied because it is a widget:
1.
This
findViewById(R.id.textview).setMovementMethod(new MovementMethod());
does not work, since findViewById is not available in AppWidgetProvider but only in Activity.
2.Putting a ScrollView around the TextView also does not work, because I get an
InflateException:
android.view.InflateException: Binary XML file line #23: Error inflating class ScrollView
Can anybody give me a hint, how to make a TextView in a Widget scrollable?
I solved this problem by putting the text view inside ListView with single node, which is supported in App widget.
http://developer.android.com/guide/topics/appwidgets/index.html#collections
It looks like this is not possible.
More on this can be found here: http://code.google.com/p/android/issues/detail?id=9580
and here:
How to make a scrollable app widget?
So, probably it is possible to do make appwidgets scrollable in the HTC sense environment but not for normal android environments.
A way around this is to add buttons that go up and down in a list.
I have been working on this with two buttons which increment and decrement through an array. Just having trouble accessing the global variables. Did you make any headway on this?
Another solution is:
Add to textview any web link - for example: www.google.com.
Setting text value with HtmlCompat.fromHtml method:
textView.setText(HtmlCompat.fromHtml("some text" + "\nwww.google.com", HtmlCompat.FROM_HTML_MODE_COMPACT));
After that vertical scrollbar is appeared.
But it's not elegant and full solution. It's temporary workaround maybe...
The complete full solutiion is bat-el-g 's answer - with adding ListView.
Current marked solution (which just tell: "it's not possible") - is wrong.
In mainactivity.java:
after code text view:
TextView txt = (TextView) findViewById(R.id.textView id);
Enter this code:
txt.setMovementMethod(new ScrollingMovementMethod());
and you will be ok.
Related
I have a image "myXmlImage" in my .xml file
In the .kt file, I want to paste another "newImage" image as well as a little text "newText".
myXmlImage.setImageDrawable(newImage.drawable)
myXmlImage.imageMatrix = newImage.imageMatrix
So far it has been working very well and the new image is in place.
I'm completely stuck on how to paste the little "newText" into it
Any ideas will be greatly appreciated, thanks in advance.
Perhaps there's more than what you've described here. But if those are really your only specifications, then what you're asking for is really easy.
I'm assuming that your xml file has a root of ConstraintLayout. If it doesn't, then you're going to either want to change it or at least wrap your ImageView inside of a ConstraintLayout.
Use the layout editor to place a TextView inside of your ImageView (NOT AS A CHILD; when I say "inside", I mean spacially inside). If you haven't used the layout editor very much, it might take you a couple of tries to place the TextView inside. Don't just drag it into the ImageView as if it were a child. Drag it and drop it under the ImageView inside of the ConstraintLayout and then use little circles on the sides to attach it to the sides of the ImageView. Don't forget to set the text of the TextView as "".
(I'm not actually sure if this step is necessary because I don't know what the default background of a TextView is, but I do it out of habit.)When you're done placing that TextView inside of the ImageView, go the code of your xml file and use android:background="#00FFFFFF" (or maybe somewhere in your project you have either a transparent background drawable or a transparent #color that you can reference by name).
I'm sure you know the rest. Just give that TextView an Id like newtext and inside of your activity retrieve the view: newText:TextView=findViewById(R.id.newtext). And then set the text: newText.text="new text".
I've got a problem and have no idea how to fix it. I'm using a ConstraintLayout in android
I want to set my TextView to wrap_content programmatically but respect my constraints.
Now the issue is that if i set my constriantWidth to WRAP_CONTENT it does not respect the constraints it's given to it.
I've found that there is a solution in xml in it here:
Wrap_content view inside a ConstraintLayout stretches outside the screen
but in this issue no where is it described how to set the property of constrainedwidth to true programmaticly.
I've tried a few things but have not found a solution to my problem:
set.constrainWidth(textView.getId(),ConstraintSet.WRAP_CONTENT)
just wraps the content without keeping in my constriants that i've set.
I've also tried to set the constraintedWidth with the ConstraintLayout.Params but nothing happend.
And i have no clue if en how i can set constrainedWidth in my ConstraintSet.
and
set.constrainWidth(textView.getId(),ConstraintSet.MATCH_CONSTRAINT_WRAP)
Just makes my text a thin line of my text and doesn't show my text anymore.
If someone could help i would be very great full.
PS. Sorry for my english not a native speaker.
Use constrainDefaultWidth:
set.constrainDefaultHeight(textView.getId(), ConstraintSet.MATCH_CONSTRAINT_WRAP);
I have this fragment layout where some content needs to be animated (like showing/hiding input field).
Now I found out I could manage this by using a fancy animation (by using <item name="android:animateLayoutChanges">true</item> on a linear layout).
The problem I have here is that I need to add al content programmatically..
For example
LinearLayout timesheetsWrapper = (LinearLayout)inflatedView.findViewById(R.id.new_timesheet_wrapper);
EditText timeSheetName = new EditText(getContext());
timeSheetName.setHint("Name");
timesheetsWrapper.addView(timeSheetName);
Now image I need to add like 10 GUI components and style each one of them programmatically, which is a bit of a hassle to me.
Is there a way that I could add a partial layout .xml file into the 'wrapper'?
For instance:
LinearLayout partialLayout = ...??
timesheetsWrapper.addView(partialLayout);
Where the partialLayout.xml contains all the GUI components.
Already searched around but it all got a bit confusing to me!
I hope my question is a bit clear, if not (or additional info is needed) I'am happy to edit/provide.
Thanks in advance, regards an android noob
I have created an EditText object dynamically but I haven't been able to create a multi-line EditText. I have tried this:
EditText et1 = new EditText(this);
et1.setHint("Enter Your Address");
et1.setSingleLine(false);
et1.setHorizontalScrollBarEnabled(false);
et1.setInputType(android.text.InputType.TYPE_TEXT_VARIATION_POSTAL_ADDRESS);
et1.setLines(7);
Thanks.
Include this in your code:
et1.setMaxLines(maxlines);
Or you can set the specific height for the edit text.
If you want the text to wrap to the next line, add TYPE_CLASS_TEXT to the MULTI_LINE flag:
textArea.setInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_FLAG_MULTI_LINE);
It is the line:
et1.setInputType(android.text.InputType.TYPE_TEXT_VARIATION_POSTAL_ADDRESS);
that is the problem. Take that out.
setMaxLines doesn't matter much unless you want to set a max number of lines. You should also avoid setting the height to something specific. WRAP_CONTENT works great.
Even changing it to:
et1.setInputType(android.text.InputType.TYPE_TEXT_FLAG_MULTI_LINE);
forces it to a single line edit, which seems odd.
This doesn't work either:
et1.setInputType(android.text.InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
which is really freakin irritating. Seems like an android bug...
You also might want to set the vertical scroll on and gravity so it can scroll up and down and starts in the top left.
et1.setGravity(Gravity.TOP|Gravity.LEFT);
et1.setVerticalScrollBarEnabled(true);
What worked for me is:
et1.setSingleLine(false);
et1.setHorizontalScrollBarEnabled(false);
et1.setVerticalScrollBarEnabled(true);
et1.setMinLines(minLines);
I have a TextView and I want to increase its height on runtime.
I have used android:layout_height="wrap_content" but it did not gave me the desired result.
I'm using a Relative Layout.
i get text through edittext and i want to set it on textview.
when i do this it shows only one line, and when i click on edittext it get expanded and full message is shown.
Add in Oncreate method of your
Activity class,
((TextView)
findViewById(R.id.YOURTEXTVIEWIDHERE)).setHeight(IntegerValuePixels);
hard to tell without more details - but do you really need to change it on runtime? because obviously you're not happy with the height at startup.
have you thought about using android:layout_height="fill_parent", eventually in combination with the android:minHeight attribute of other components?