use of android.widget.EditText in project robolectric by robolectric.
the class ShadowEditTextTest method givenInitializingWithAttributeSet_whenMaxLengthDefined_thenRestrictTextLengthToMaxLength.
@Test
public void givenInitializingWithAttributeSet_whenMaxLengthDefined_thenRestrictTextLengthToMaxLength() {
int maxLength = anyInteger();
AttributeSet attrs = Robolectric.buildAttributeSet().addAttribute(android.R.attr.maxLength, maxLength + "").build();
EditText editText = new EditText(RuntimeEnvironment.application, attrs);
String excessiveInput = stringOfLength(maxLength * 2);
editText.setText(excessiveInput);
assertThat((CharSequence) editText.getText().toString()).isEqualTo(excessiveInput.subSequence(0, maxLength));
}
use of android.widget.EditText in project robolectric by robolectric.
the class ShadowEditTextTest method shouldGetHintFromXml.
@Test
public void shouldGetHintFromXml() {
Context context = RuntimeEnvironment.application;
LayoutInflater inflater = LayoutInflater.from(context);
EditText editText = (EditText) inflater.inflate(R.layout.edit_text, null);
assertThat(editText.getHint().toString()).isEqualTo("Hello, Hint");
}
use of android.widget.EditText in project robolectric by robolectric.
the class ShadowEditTextTest method givenInitializingWithAttributeSet_whenMaxLengthNotDefined_thenTextLengthShouldHaveNoRestrictions.
@Test
public void givenInitializingWithAttributeSet_whenMaxLengthNotDefined_thenTextLengthShouldHaveNoRestrictions() {
AttributeSet attrs = Robolectric.buildAttributeSet().build();
EditText editText = new EditText(RuntimeEnvironment.application, attrs);
String input = anyString();
editText.setText(input);
assertThat(editText.getText().toString()).isEqualTo(input);
}
use of android.widget.EditText in project robolectric by robolectric.
the class ShadowEditTextTest method setup.
@Before
public void setup() {
AttributeSet attributeSet = Robolectric.buildAttributeSet().addAttribute(android.R.attr.maxLength, "5").build();
editText = new EditText(application, attributeSet);
}
use of android.widget.EditText in project mobile-android by photo.
the class TagsFragment method init.
public void init(View v) {
final EditText search = (EditText) v.findViewById(R.id.edit_search);
search.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (event != null) {
switch(event.getKeyCode()) {
case KeyEvent.KEYCODE_ENTER:
CommonUtils.debug(TAG, "Key code enter");
if (KeyEvent.ACTION_DOWN == event.getAction()) {
CommonUtils.debug(TAG, "Opening gallery");
search.post(new Runnable() {
@Override
public void run() {
galleryOpenControl.openGallery(search.getText().toString().trim(), null);
}
});
return true;
}
break;
}
}
return false;
}
});
Button filterBtn = (Button) v.findViewById(R.id.filterBtn);
filterBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
TrackerUtils.trackButtonClickEvent("filterBtn", TagsFragment.this);
galleryOpenControl.openGallery(mAdapter.getSelectedTags(), null);
}
});
refresh(v);
}
Aggregations