Struggling To Launch Numeric Keypad On Activity Start
I have few TextView's in my activity, when activity starts i want to show soft numeric keypad or that activity should always show keypad. I have tried: To set android:windowSoftIn
Solution 1:
I have tried this for an EditText in a dynamic way...The method would be the same for TextView also..When activity starts,give focus on that textView ,so that it can show u the keypad
boolean checkFocus=EditText.requestFocus();
Log.i("CheckFocus", ""+checkFocus);
if(checkFocus==true)
{
InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
EditText.setInputType(InputType.TYPE_CLASS_PHONE); [select Inputtypeas according to ur requirement]
mgr.showSoftInput(EditText, InputMethodManager.SHOW_IMPLICIT);
}
Solution 2:
Place edit text in your xml file as first child.
<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android".....................><EditTextandroid:layout_width="0dp"android:layout_height="0dp"/>
..............
................
</LinearLayout>
Solution 3:
To pop up a numeric keyboard on start of the activity i used following steps:
Created edit text field in layout as:
<EditText...android:inputType="number"... />
but since you need the key board to be poped without any edit text so give
<EditText...android:layout_width="0dp"android:layout_height="0dp"android:inputType="number"... />
In function onCreate() show soft keyboard
InputMethodManagerimm= (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
Most important is to give focus to edit text in onResume method.
@OverridepublicvoidonResume() {
super.onResume();
editText.setFocusableInTouchMode(true);
editText.requestFocus();
}
Post a Comment for "Struggling To Launch Numeric Keypad On Activity Start"