How to disable vertical scroll of EditText? - java

I create EditText programmatically.
Following is my code:
mEditText = new EditText(mMainActivity);
mEditText.setVisibility(View.INVISIBLE);
mEditText.setTextSize(8);
mEditText.setSingleLine();
mEditText.setMaxLines(1);
mEditText.setLines(1);
mEditText.setVerticalScrollBarEnabled(false);
What I set above seems completely useless...Please help me.

You can try setMovementMethod() It will disable the EditText text scrolling. But you have to manage text size.
eText.setMovementMethod(null);
Hope it will help you...

Set below properties:
mEditText.setSingleLine(true);
mEditText.setHorizontallyScrolling(true);
It will work.

What input type do you want?
editText.setInputType(InputType.TYPE_**);
if email/phone you do not even need the
editText.setLines(1);
editText.setMaxLines(1);
Also note your method
editText.setSingleLine(false);
May be changing the values on your maxLines and Lines methods.

Related

CheckBoxListComboBox unseelct the selection programatically

I am using com.jidesoft.combobox.CheckBoxListComboBox
I made the selection of the checkboxes programatically with
int[] indecesToSelect =..
combo.setSelectedIndices(indecesToSelect);
But i dont see any way to unselect any selection.
I tried
combo.setSelectedItem(item, false);
But this is not unselecting , this is also selecting
Also tried
combo.getList().clearSelection();
no effect
Please help
use combo.setSelectedIndex(-1); to unselect.
Source

Changing an ImageResource (drawable) programmatically

I am currently using the #android:drawable/presence_online as the srcCompat for a ImageView.
I would like to change it programmatically to #android:drawable/presence_offline.
I tried the code below but it didn't work.
final ImageView imgPresence = (ImageView) findViewById(R.id.imgPresence);
imgPresence.setImageResource(R.drawable.presence_offline);
Any ideas?
You missed android in the resource id.
Instead of
imgPresence.setImageResource(R.drawable.presence_offline);
use this:
imgPresence.setImageResource(android.R.drawable.presence_offline);
Though commented by #Srijith, I am putting as an answer here:
Change the below line
setImageResource(R.drawable.presence_offline);
to
setImageResource(android.R.drawable.presence_offline);
try this:
imgPresence.setImageResource(getResources().getDrawable(R.drawable.presence_offline));

Robotium: How can get I get the id of a view? OR how can I sent text directly to a view?

I'm trying to send text to a view that I know the id of. It seems enterText() wants an int, but all I have is a view.
solo.enterText(solo.getView(R.id.et_firstname_insurance), firstName);
Ideas? I read the API documentation and can't figure it out.
I figured it out with the help of my coworker. This turns the view into an EditText object, which can be passed into one of the flavors of enterText:
public static EditText getEditText(int i) {
return (EditText) solo.getCurrentActivity().findViewById(i);
}
EditText eFn = RobotiumHelpers.getEditText(R.id.et_firstname_insurance);
solo.enterText(eFn, firstName);
I'm pretty sure that this is not allowed. Robotium is testing purposes and if you're changing the whole state of the activity externally than that defeats the purpose and might possibly have the ability to do damage. Now if you're talking about entering text in something that is editable than the int is the editable field number. Check out the tutorial
you can assign this to a view as view1 and then you can use
solo.enterText(view1, firstName);
and if that also doesn't work try using solo.clickOnView(view1);
and after that solo.enterText(view1, firstName);
What worked for me - assertTrue("btnUseEmailToLogin View is not visible", (solo.getView("idName") ).isShown() == true);
Where idName - is the id of desired view to check

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

Android development toggling TextView visibility

Im having some trouble with setting textview to invisible/visible.
basicly i want this to happen when an on/off button has been clicked.
what i did is kind of like
textview.setVisibility(TextView.VISIBLE);
textview.setVisibility(TextView.INVISIBLE);
when i try executing this the emultor says that the app has stopped unexcpetedly
Are you building this from XML or programmatically?
I would make it with an XML file then when the Activity runs change the property. Be sure to use setContentView(R.layout.main); before you try to get the TextView with findViewById(...).
Call .setVisibility(View.GONE); on the TextView to hide it.
Call .setVisibility(View.VISIBLE); to on the TextView to show it.
I have an example that does something like this. You can see the code here: https://github.com/ethankhall/Morse-Messenger/blob/master/src/com/kopysoft/MorseMessenger/Translate.java
Without more code or a stack trace, it's hard to say, but it sounds like you haven't initialized the text view. Here's how to do it:
TextView myTextView = (TextView) findViewById(R.id.tv_text);
Where 'tv_text' is the id of the textview as defined in the xml layout file.
Hope that helped!
Read about DDMS and logcat to obtain a stacktrace and to see what the problem is: http://developer.android.com/guide/developing/debugging/debugging-projects.html
This is what you are looking for:

Categories