How to show the line break button in Android keypad? - java

I am building a text area in my APP using a TextInputLayout and its multiline property to let the users write more than 1 line, I am building it programatically (no xml)
TextInputLayout textInputLayout = new TextInputLayout(context);
textInputLayout.setLayoutParams(new TextInputLayout.LayoutParams(TextInputLayout.LayoutParams.MATCH_PARENT, TextInputLayout.LayoutParams.WRAP_CONTENT));
TextInputEditText field = new TextInputEditText(context);
field.setText(text);
field.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE);
field.setLayoutParams(new TextInputLayout.LayoutParams(TextInputLayout.LayoutParams.MATCH_PARENT,(int) (100 * dp)));
textInputLayout.addView(field);
myLinearLayout.addView(textInputLayout); // add text to layout
The code above makes my textarea, but is not showing the line break button, it shows a submit button instead.
This is the current result:
This is the expected result (from another app):
Which property I have to add to show the line break button like the second image?

How to get the keyboard to show a return key?
Try setting IMEOptions as None.
field.setImeOptions(EditorInfo.IME_ACTION_NONE);
Also check if the EditText has become SingleLine that also causes the done button to appear.

Related

Android: In tabbed app, textView output is not consistant with LogCat

In my app which has tabbed activity, I am sending a simple message to textView and logcat (message indicating which tab I am selecting).
However, textView shows correct string but logcat shows different one.
Steps to reproduce this problem are very simple:
Start a new Android Studio project (My Android Studio version: 1.5.1)
Give any application name (e.g. MyApplication)
Keep only "Phone and Tablet" selected
Select "Tabbed Activity"
Choose Navigation Style "Action Bar Tabs (with View Pager)"
Click finish
This will generate and build project. If we run this application it will show string "Hello World from section: 1" on first tab, "Hello World from section: 2" on second and "Hello World from section: 3" on third tab.
Now, go in MainActivity.java and in method onCreateView (of class PlaceholderFragment) just below this line (where it send string to textView),
textView.setText(getString(R.string.section_format, getArguments().getInt(ARG_SECTION_NUMBER)));
add this line
Log.i("onCreateView", "From tab number: " + getArguments().getInt(ARG_SECTION_NUMBER));
Expected behaviour:
textView and logcat both should display same message as we tap on tabs.
Actual behaviour:
textView shows correct strings. However in logcat, tab numbers shown are incorrect and hence not in consistent with textView output.
This is indeed weird and height of all is, instead of this when I tried forming string on my own and passing it to textView and LogCat
String strMessage = "Msg from tab number: " + getArguments().getInt(ARG_SECTION_NUMBER);
textView.setText (strMessage);
Log.i("onCreateView", strMessage);
It still has SAME behaviour i.e. shows correct strings in textView for relevant tabs but Logcat shows completely different tab numbers. Same string I am sending but only number changes ???
I found root cause of this on my own. Looks like textView.setText called in onCreateView sets the text value and it never changes afterwards. I wanted to find out which tab currently is active or visible so that I could update its contents. And I was under wrong impression that onCreateView gets called when tab is visible. Finally I found this answer which solved my problem.

Android java : Dealing whith xml's parsed String

I have an xml which Text looks like this :
<LINE>here is some text, it is going,going, and then return is pressed
and the text is going from the next line</LINE>
now when I do :
XmlPullParcer xpp;
//then all the parcing, try/catch stuff, finding needed tag
String s=xpp.getText();
myTextView.setText(s);
(of course, I cut all the code, but you got the idea)
what I see on the screen is not one solid line with no formatting as I wish, but the same two-line text
So, what I see on the screen is :
here is some text, it is going,going, and then return is pressed
and the text is going from the next line
and I want :
here is some text, it is going,going, and then return is pressed and but text is going in one line
please tell me how can I process my String s so it can be shown in a TextView in one line
It looks like the line in XML itself is having a line feed or carriage return. So try to replace them with empty string via String replace method. You can refer to link below for more details:
http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html#sum
Also make sure the TextView in layout has singleline attribute set to true and layout_width set to match_parent.

Press 'Go' button of keyboard using Android UI Automator

I am unable to press 'Go' button on searching something on Nexus 7' tablet. We don't have any text or content description for the 'Go' button on the keyboard. I tried using following -
//Search something say "fun"
new UiObject(new UiSelector().text("Enter URL or Search & Win")).setText("fun");
getUiDevice().pressEnter();
OR
getUiDevice().pressSearch();
Also tried :
getUiDevice().pressKeyCode(66); //for enter
getUiDevice().pressKeyCode(84); // for search
But this is not working.
Could anyone help me out with this.
Thanks
Try using the button attribute with reference to index.
i.e :
UiObject cancelButton = new UiObject(new UiSelector().className("android.widget.Button"));
To click on "Done" button with UIAutomator just try below code
use
just make sure that correct layout in which input keyboard is open is used
UiObject(new UiSelector().resourceId(LAYOUTID)).clickBottomRight();

Tripleplay Button: Dynamic text with proper alignment on an Image Button (say the text justified , centre)

I am creating a window with two image buttons (using TriplePlay in my playN game).
Now I need dynamic text on these buttons. But when I add buttons with images (setIcon), I am not able to add Text on it same time. Please check the following code block I use now.
Interface iface = new Interface(null);
pointer().setListener(iface.plistener);
Styles buttonStyles = Styles.none().add(Style.BACKGROUND.is(new NullBackground())).
addSelected(Style.BACKGROUND.is(Background.solid(0xFFCCCCCC)));
Stylesheet rootSheet = Stylesheet.builder().add(Button.class, buttonStyles).create();
Root buttonroot = iface.createRoot(AxisLayout.horizontal().gap(150), rootSheet);
buttonroot.setSize(width_needed, height_needed);
buttonroot.addStyles(Styles.make(Style.BACKGROUND.is(new NullBackground())));
graphics().rootLayer().add(buttonroot.layer);
Button you = new Button().setIcon(buttonImage);
Button friend = new Button().setIcon(buttonImage);
buttonroot.add(you).add(friend);
buttonroot.layer.setTranslation(x_needed, y_needed);
Root nameroot = iface.createRoot(AxisLayout.horizontal().gap(300), rootSheet);
nameroot.setSize(width_needed, height_needed);
nameroot.addStyles(Styles.make(Style.BACKGROUND.is(new NullBackground())));
graphics().rootLayer().add(nameroot.layer);
name = new Label("YOU");// we need the dynamic string variable instead
friendName = new Label("FRIEND"); // we need the dynamic string variable instead
nameroot.add(name).add(friendName);
nameroot.layer.setTranslation(x_needed, y_needed);
here I have tried making a root then add button with images to it then making another root and add labels on it so that it will be show like text on the image buttons. But I know this is a bad way of doing it, and the alignment will not be according to what needed as it a dynamic text. Is there anyway to add a button, with image and a label on it?
Thanks in anticipation
Creating a button with text and an icon is trivial:
Button button = new Button("Text").setIcon(iconImage);
You can then change the text on the button any time you like, like so:
button.text.update("New Text");
If you want a button with a background image with text rendered over the background, then do the following:
Button button = new Button("Text").
addStyles(Background.is(Background.image(bgImage)));
Note that you will need the latest TriplePlay code (from Github) to use the ImageBackground. The latest code also supports Flash-style "scale9" backgrounds:
Button button = new Button("Text").
addStyles(Background.is(Background.scale9(bgImage)));

Vaadin Checkbox -- Add a newline on caption

I am trying to set the caption of a checkbox and i want to break at a certain point in the string to create a new line without waiting for the word wrap:
When i added the simple \n character to caption string it did not work.
private CheckBox completeCheckbox;
completeCheckbox.setCaption("why wont this\n break");
I just had the same problem and the simple solution for this was to call "setCaptionAsHtml(true)" on the CheckBox instance and to set the caption using HTML code.
private CheckBox completeCheckbox = createMyCheckboxSomehowFunction();
completeCheckbox.setCaptionAsHtml(true);
completeCheckbox.setCaption("why wont this<br/>break");
The above code snippet should do what you want. At least it worked fine for me.
i think the solution is to use an Option Group
I just read that here

Categories