Use NumberPicker as Input Method instead of standard keyboard - java

I have several EditText fields in my Activity. For one of those fields I like to use a NumberPicker to enter the values (e.g. age, height or whatever). Is there a possibility to display a NumberPicker instead of the keyboard once that specific editText is clicked?
I know that you can change the inputType to "text", "numberPassword" etc. in the layout file but I haven't found a possibility to make that inputType a customView.

You can set the input type of your edit text "None" and set focusable to false.
<EditText
android:inputType="none"
android:id="#+id/editText"
android:focusable="false"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
And in your java file, you can set an onClickListener in your edit text, where you can show NumberpickerView in a dialog or something and from there set the value in edit text. To show number picker as a dialog, you can refer to the stackoverflow link in the comment on your question.

Related

How to hide IME when EditText is focused

I want EditText not to extend IME when it is focused on Android Wear.
I read and implemented in the same way as the following thread:
Prevent EditText from automatically focusing
However, IME appears.
Is it impossible to hide IME for an EditText on Android Wear?
I tried 3 methods:
Added the following code in the onCreate() method:
{getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);}
Added the following code in the activity tag in AndroidManifest.xml
android:windowSoftInputMode="stateAlwaysHidden"
Added the following code in rect_activity_main.xml
<LinearLayout
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#android:color/transparent"
android:focusable="true" android:focusableInTouchMode="true"/>
None of them worked.
Best regards, gellpro
Check Show the Input Method On Demand. It's noted that the system hides the input method when the user finishes the task in the test field or the user can hide it with a system control. With this, try to specify how your UI should respond. It's mentioned that,
To declare your preferred treatment in an activity, use the android:windowSoftInputMode attribute in your manifest's element with one of the "adjust" values.
Then, to implement hiding IME, try using InputMethodManager with constant set to RESULT_UNCHANGED_HIDDEN. This will flag for the ResultReceiver result code from showSoftInput(View, int, ResultReceiver) and hideSoftInputFromWindow(IBinder, int, ResultReceiver): the state of the soft input window was unchanged and remains hidden.
Hope that helps.

Android Search icon on keyboard WITHOUT moving to next element

This may seem like a dumb question, but I want the magnifying glass on the keyboard, but I don't want the focus to go right to the next element.
I've got an EditText that populates a ListView with possible matches to the user's query. The EditText's XML includes
"android:imeOptions="actionSearch"
which adds the search icon. But it also takes the user to the first element of the ListView which is really annoying.
Is there a way to include the search icon AND not force focus to the ListView?
EDIT:
By request, my EditText xml. Sorry in advance if I mess up the formatting somehow.
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/editSearchWord"
android:imeOptions="actionSearch|normal"
android:inputType="text"
android:drawableLeft="#android:drawable/ic_menu_search"
android:layout_alignParentStart="true"/>

Android edittext attributes

I have 2 edittext fields in an app.
Depending on which radio button is selected one of these fields is disabled.
The problem is that when the top field is enabled the user types in a double and then there is no option to be "done" with the keyboard because it still considers that the next field needs to be filled in even though it's disabled.
How can I change this?
Include the imeOptions and singleLine attributes in your EditText.
<EditText
...
android:imeOptions="actionDone"
android:singleLine="true" />

How to use two different font sizes for button text in Android?

How could I implement a button background for ImageButton or Button which contains 2 textview each using different font sizes ? I cant use static images as background and I need to achieve this either using xml or programmatically.
This is a numeric keypad and it carries a numeric value and a set of alphabets each of which uses different font sizes and needs to be set as button text.
Here are some of the suggestions that pop-up on my brain but seems to have limitations since I want to reuse the UI component and avoid code repetition.
Create a layout xml containing 2 textfields and set that as background on the button. But how can I get a reference of these textview fields to set the value on them in the MyActivity.java?
Use a layeredlist ? still same problem reference of textviews
Or create a custom view and inflate layout mentioned in step 1. This solution resolves my problem.
Does any other solution exist for this UI requirement?
Thanks.
Hopefully this will help. This off course is not the only solution but it is a pretty simple one. Add the xml part in your xml instead of the button.
XML
<LinearLayout
android:id="#+id/button_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="5"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:text="ABC"/>
</LinearLayout>
CODE
LinearLayout button= (LinearLayout)findViewById(R.id.button_layout);
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO DO whatever you want to do here
}
});
For your button you can use code like this
don't forget put font in your Assets folder
Button btnA=(Button) findViewById(R.id.button1);
Typeface typeface = Typeface.createFromAsset(getAssets(), "yourFont.ttf");
btnA.setText("my custom font");
btnA.setTypeface(typeface);
btnA.setTextSize(20);//as per your size
and for more reference see this
do as your second button if this helps let me know thanks...

Android Autocomplete TextView drop down width

I want the dropdown of my auto complete TextView to cover the entire screen width. Currently the normal behaviour of the autocomplete textview is such that it covers only the width of the EditText (screenshot below).
How do I do it ? It should look somewhat like the default maps app in android.
http://developer.android.com/reference/android/widget/AutoCompleteTextView.html#attr_android:dropDownWidth
By putting the value -1 or fill_parent it should work
autoCompleteTextView.setDropDownWidth(getResources().getDisplayMetrics().widthPixels);
Use android:dropDownWidth="match_parent" in AutoCompleteTextView inside xml
<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:dropDownWidth="match_parent"
/>

Categories

Resources