Ever wanted to change text size, font or do HTML inside a text box?
Spannable to the rescue
Showing posts with label edittext. Show all posts
Showing posts with label edittext. Show all posts
Thursday, 20 October 2011
Thursday, 7 July 2011
Detecting done / enter on an EditText
Had some trouble detecting DONE / ACTION_FINISHED / Pressing Enter - They can all fire a bit differently on the emulator and on different phones.
stackoverflow comes to the rescue again!
stackoverflow comes to the rescue again!
myEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH ||
actionId == EditorInfo.IME_ACTION_DONE ||
event.getAction() == KeyEvent.ACTION_DOWN &&
event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
// Do something
}
return false;
});
Tuesday, 5 July 2011
EditText & removing the popup keyboard
EditText = Like a TextView but designed for entering text
Example code sourced from
The XML file:
This java code will remove the popup keyboard when Done is pressed
Adding the handler to your main Class
Example code sourced from
The XML file:
<EditText android:id="@+id/search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="search"
android:imeOptions="actionGo" />
This java code will remove the popup keyboard when Done is pressed
Adding the handler to your main Class
final EditText edittext = (EditText) findViewById(R.id.search);
edittext.setOnEditorActionListener(new TextView.OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_GO) {
// hide virtual keyboard
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(edittext.getWindowToken(), 0);
return true;
}
return false;
}
});
Subscribe to:
Posts (Atom)