本文整理匯總了Java中android.text.method.KeyListener類的典型用法代碼示例。如果您正苦於以下問題:Java KeyListener類的具體用法?Java KeyListener怎麽用?Java KeyListener使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
KeyListener類屬於android.text.method包,在下文中一共展示了KeyListener類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: editPhoneNumber
import android.text.method.KeyListener; //導入依賴的package包/類
/**
* Tapping the edit icon next to the phone number allows the user to edit their phone
*
* @param v v is a View, allows usage of on click in xml
*/
public void editPhoneNumber(View v) {
editingPhone = true;
ImageButton cancelButton = (ImageButton) findViewById(R.id.Button_cancelPhoneEdit);
ImageButton saveButton = (ImageButton) findViewById(R.id.EditButton_savePhoneEdit);
ImageButton editButton = (ImageButton) findViewById(R.id.ImageButton_phoneEditIcon);
// Set visibility of the buttons.
editButton.setVisibility(View.INVISIBLE);
saveButton.setVisibility(View.VISIBLE);
cancelButton.setVisibility(View.VISIBLE);
TextView phoneNumber = (TextView) findViewById(R.id.EditText_phone);
phoneNumber.setClickable(true);
// Set it so the user can edit the EditText
phoneNumber.setFocusableInTouchMode(true);
phoneNumber.setFocusable(true);
phoneNumber.setKeyListener((KeyListener) phoneNumber.getTag());
phoneNumber.requestFocus();
phoneNumber.moveCursorToVisibleOffset();
phoneNumber.setText("");
phoneNumber.append(currentUser.getPhone());
}
示例2: editEmailAddress
import android.text.method.KeyListener; //導入依賴的package包/類
/**
* Tapping the edit icon next to the email allows the user to edit their email
*
* @param v v is a View, allows usage of on click in xml
*/
public void editEmailAddress(View v) {
editingEmail = true;
ImageButton cancelButton = (ImageButton) findViewById(R.id.ImageButton_cancelEmailEdit);
ImageButton saveButton = (ImageButton) findViewById(R.id.EditButton_saveEmail);
ImageButton editButton = (ImageButton) findViewById(R.id.ImageButton_emailEditIcon);
// Set visibility of the buttons.
editButton.setVisibility(View.INVISIBLE);
saveButton.setVisibility(View.VISIBLE);
cancelButton.setVisibility(View.VISIBLE);
EditText emailView = (EditText) findViewById(R.id.EditText_email);
// Set it so the user can edit the EditText
emailView.setFocusableInTouchMode(true);
emailView.setClickable(true);
emailView.setKeyListener((KeyListener) emailView.getTag());
emailView.requestFocus();
emailView.setText("");
emailView.append(currentUser.getEmail());
}
示例3: setKeyListener
import android.text.method.KeyListener; //導入依賴的package包/類
/**
* Sets the key listener to be used with this TextView. This can be null
* to disallow user input. Note that this method has significant and
* subtle interactions with soft keyboards and other input method:
* see {@link KeyListener#getInputType() KeyListener.getContentType()}
* for important details. Calling this method will replace the current
* content type of the text view with the content type returned by the
* key listener.
* <p>
* Be warned that if you want a TextView with a key listener or movement
* method not to be focusable, or if you want a TextView without a
* key listener or movement method to be focusable, you must call
* {@link #setFocusable} again after calling this to get the focusability
* back the way you want it.
*
* @attr ref android.R.styleable#TextView_numeric
* @attr ref android.R.styleable#TextView_digits
* @attr ref android.R.styleable#TextView_phoneNumber
* @attr ref android.R.styleable#TextView_inputMethod
* @attr ref android.R.styleable#TextView_capitalize
* @attr ref android.R.styleable#TextView_autoText
*/
public void setKeyListener(KeyListener input) {
setKeyListenerOnly(input);
fixFocusableAndClickableSettings();
if (input != null) {
try {
mInputType = mInput.getInputType();
} catch (IncompatibleClassChangeError e) {
mInputType = EditorInfo.TYPE_CLASS_TEXT;
}
if ((mInputType&EditorInfo.TYPE_MASK_CLASS)
== EditorInfo.TYPE_CLASS_TEXT) {
if (mSingleLine) {
mInputType &= ~EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE;
} else {
mInputType |= EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE;
}
}
} else {
mInputType = EditorInfo.TYPE_NULL;
}
InputMethodManager imm = InputMethodManager.peekInstance();
if (imm != null) imm.restartInput(this);
}
示例4: getKeyListenerForType
import android.text.method.KeyListener; //導入依賴的package包/類
/** gets the key listener by type */
private static KeyListener getKeyListenerForType(NumericType type) {
switch (type) {
case DIALPAD:
return new DialerKeyListener();
case INTEGER:
return new DigitsKeyListener();
case SIGNED:
return new DigitsKeyListener(true, false);
case DECIMAL:
return new DigitsKeyListener(true, true);
case NONE:
default:
return null;
}
}
示例5: createView
import android.text.method.KeyListener; //導入依賴的package包/類
/** {@inheritDoc} */
@Override
protected View createView(Context c) {
et = new EditText(c);
et.setText(answer);
et.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
if (!NumericType.NONE.equals(numericType)) {
KeyListener listener = getKeyListenerForType(numericType);
if (listener != null)
et.setKeyListener(listener);
} else {
et.setRawInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES |
TYPE_TEXT_FLAG_NO_SUGGESTIONS);
}
return encapsulateQuestion(c, et);
}
示例6: getKeyListenerForType
import android.text.method.KeyListener; //導入依賴的package包/類
/** gets the key listener by type */
protected static KeyListener getKeyListenerForType(NumericType type) {
switch (type) {
case DIALPAD:
return new DialerKeyListener();
case INTEGER:
return new DigitsKeyListener();
case SIGNED:
return new DigitsKeyListener(true, false);
case DECIMAL:
return new DigitsKeyListener(true, true);
case NONE:
default:
return null;
}
}
示例7: createView
import android.text.method.KeyListener; //導入依賴的package包/類
/** {@inheritDoc} */
@Override
protected View createView(Context c) {
et = new EditText(c);
et.setBackgroundResource(R.drawable.oval);
et.setTextColor(c.getResources()
.getColorStateList(R.color.primary_text_holo_light));
et.setText(answer);
et.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
if (!NumericType.NONE.equals(numericType)) {
KeyListener listener = getKeyListenerForType(numericType);
if (listener != null)
et.setKeyListener(listener);
} else {
et.setRawInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES |
TYPE_TEXT_FLAG_NO_SUGGESTIONS);
}
return encapsulateQuestion(c, et);
}
示例8: setReadOnly
import android.text.method.KeyListener; //導入依賴的package包/類
@Override
public void setReadOnly(boolean value) {
KeyListener keyListener = getKeyListener();
if (value) {
setKeyListener(null);
} else {
if (keyListener != null)
setKeyListener(keyListener);
}
}
示例9: setKeyListenerOnly
import android.text.method.KeyListener; //導入依賴的package包/類
private void setKeyListenerOnly(KeyListener input) {
if (mEditor == null && input == null) return; // null is the default value
createEditorIfNeeded();
if (mEditor.mKeyListener != input) {
mEditor.mKeyListener = input;
if (input != null && !(mText instanceof Editable)) {
setText(mText);
}
setFilters((Editable) mText, mFilters);
}
}
示例10: setEditable
import android.text.method.KeyListener; //導入依賴的package包/類
static void setEditable( EditText et, MyKeyboard kbd, KeyListener kl, boolean editable, int flag )
{
if ( TDSetting.mKeyboard ) {
et.setKeyListener( null );
et.setClickable( true );
et.setFocusable( editable );
if ( editable ) {
registerEditText( kbd, et, flag );
// et.setKeyListener( mKeyboard );
et.setBackgroundResource( android.R.drawable.edit_text );
} else {
registerEditText( kbd, et, flag | FLAG_NOEDIT );
et.setBackgroundColor( TDColor.MID_GRAY );
}
} else {
if ( editable ) {
et.setKeyListener( kl );
et.setBackgroundResource( android.R.drawable.edit_text );
et.setClickable( true );
et.setFocusable( true );
} else {
// et.setFocusable( false );
// et.setClickable( false );
et.setKeyListener( null );
et.setBackgroundColor( TDColor.MID_GRAY );
}
}
}
示例11: setEditable
import android.text.method.KeyListener; //導入依賴的package包/類
private void setEditable( EditText et, KeyListener kl, boolean editable, int flag )
{
if ( TDSetting.mKeyboard ) {
et.setKeyListener( null );
et.setClickable( true );
et.setFocusable( editable );
if ( editable ) {
MyKeyboard.registerEditText( mKeyboard, et, flag );
// et.setKeyListener( mKeyboard );
et.setBackgroundResource( android.R.drawable.edit_text );
} else {
MyKeyboard.registerEditText( mKeyboard, et, flag | MyKeyboard.FLAG_NOEDIT );
et.setBackgroundColor( TDColor.MID_GRAY );
}
} else {
if ( editable ) {
et.setKeyListener( kl );
et.setBackgroundResource( android.R.drawable.edit_text );
et.setClickable( true );
et.setFocusable( true );
} else {
// et.setFocusable( false );
// et.setClickable( false );
et.setKeyListener( null );
et.setBackgroundColor( TDColor.MID_GRAY );
}
}
}
示例12: setKeyListenerOnly
import android.text.method.KeyListener; //導入依賴的package包/類
private void setKeyListenerOnly(KeyListener input) {
mInput = input;
if (mInput != null && !(mText instanceof Editable))
setText(mText);
setFilters((Editable) mText, mFilters);
}
示例13: clearMetaKeyStates
import android.text.method.KeyListener; //導入依賴的package包/類
public boolean clearMetaKeyStates(int states) {
final Editable content = getEditable();
if (content == null) return false;
KeyListener kl = mTextView.getKeyListener();
if (kl != null) {
try {
kl.clearMetaKeyState(mTextView, content, states);
} catch (AbstractMethodError e) {
// This is an old listener that doesn't implement the
// new method.
}
}
return true;
}
示例14: processKeyDown
import android.text.method.KeyListener; //導入依賴的package包/類
/**
* onKeyDown()
*/
@Override
public boolean processKeyDown(int keyCode, KeyEvent event) {
if (mEchoEditText != null && (keyCode == KeyEvent.KEYCODE_VOLUME_UP || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)) {
KeyListener keyListener = mEchoEditText.getKeyListener();
keyListener.onKeyDown(mEchoEditText, mEchoEditText.getEditableText(), keyCode, event);
return true;
}
return false;
}
示例15: processKeyUp
import android.text.method.KeyListener; //導入依賴的package包/類
/**
* onKeyUp()
*/
@Override
public boolean processKeyUp(int keyCode, KeyEvent event) {
if (mEchoEditText != null && (keyCode == KeyEvent.KEYCODE_VOLUME_UP || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)) {
KeyListener keyListener = mEchoEditText.getKeyListener();
keyListener.onKeyUp(mEchoEditText, mEchoEditText.getEditableText(), keyCode, event);
return true;
}
return false;
}