In my application I have EditText and Button and for this editText I set actionDone for imeOption.
My EditText code :
<EditText
android:id="#+id/infoSerialFrag_rememberSwitchText"
android:layout_width="#dimen/size30"
android:layout_height="match_parent"
android:layout_toRightOf="#+id/infoSerialFrag_rememberSwitch"
android:fontFamily="sans-serif-light"
android:gravity="center"
android:hint="7"
android:imeOptions="actionDone"
android:inputType="number"
android:maxLength="3"
android:maxLines="1"
android:textSize="#dimen/font11" />
When open keyboard show me Done in keyboard.
For Button I set one method.
I want when click on Done from keyboard, work me such as onClickListener for my Button.
My mean is : when click on Done from keyboard, call method in button.setOnClickLiostener{...}
How can I it? please help me
Use below code
editText.setOnEditorActionListener(new EditText.OnEditorActionListener() {
#Override
public boolean onEditorAction(EditText v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
view.performClick();
return true;
}
return false;
}
});
View is the button view name. You need to call performClick() method. this will execute the code which is available in onclick() call back method. Hope that answers your question
Related
I want ONLY the editText can be scroll-able. How to do it? As shown in the image below, when user enter the address, the editText becomes like that. Can someone help me, which part do I miss?
Java coding:-
final EditText yourMessage = (EditText) findViewById(R.id.contactMsg);
XML Coding:-
<EditText
android:id="#+id/contactMsg"
android:layout_width="288dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="390dp"
android:background="#FFF"
android:drawableLeft="#drawable/ic_action_clipboards"
android:ems="10"
android:hint="Message"
android:inputType="textMultiLine"
android:padding="2dp"
android:textSize="18sp" />
Solution:
You must enable scrolling inside the EditText programmatically:
contactMsg.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
if (v.getId() == R.id.inputFormComments) {
v.getParent().requestDisallowInterceptTouchEvent(true);
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_UP:
v.getParent().requestDisallowInterceptTouchEvent(false);
break;
}
}
return false;
}
});
Try it if it works.
I'm not so sure what you mean by making the editText look better, but for the Toast:
Toast.makeText(ActivityName.this, "", Toast.LENGTH_SHORT).show();
And you can place this code after the email has been sent.
I am attempting to create a calculator app. With only XML present a ripple animation like this occurs
However when I add java code, the ripple animation does not occur, everything else functions normally. Is their a way to fix this?
One button XML (foreground tag houses animation)
<ImageButton
android:id="#+id/one_button"
android:foreground="#drawable/ripple_animation_grey"
android:padding="0dp"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:layout_width="85dp"
android:layout_height="85dp"
app:srcCompat="#drawable/one_button_500_500"
android:layout_below="#+id/four_button"
android:layout_alignParentStart="true" />
One button java code
one_button_IB.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (!is_additon_selected) {
updateScreen("1");
} else {
values.add(current_screen_value);
clearScreen("1");
is_additon_selected = true;
additionButtonActions();
System.out.println(values);
}
}
});
i have implemented a recycler view with edit text for input quantity, after entering the quantity in edit text and calling a method my cursor is moving to next recyler edit text, pulling keyboard again.
<EditText
android:layout_width="30dp"
android:layout_height="wrap_content"
android:textSize="14dp"
android:textColor="#333f50"
android:id="#+id/edt_Quantity"
android:text="1"
android:cursorVisible="false"
android:maxLength="2"
android:background="#android:color/transparent"
android:imeOptions="actionDone"
android:inputType="number"
android:padding="5dp" />
we have tried disabling cursor by default in xml and enabling it with following code
holder.edtQuantity.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View view, boolean hasFocus) {
holder.edtQuantity.setCursorVisible(true);
}
});
i am expecting the cursor to get invisible(preventing from moving to next recycler) once i call a method associated with it.
Any help will be appreciated.
when you press done button in keyboard is clearFocus of edittext.
holder.edtQuantity.setOnEditorActionListener(new TextView.OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
holder.edtQuantity.clearFocus();
}
return true;
}
});
I have an EditText inside of a ScrollView which is pre-filled with a dynamic amount of text. It could be one line or 50 or more. At this point, the EditText is uneditable and the text is shown just fine. However, when I press a button to make the edit text editable, the entire contents of the EditText are thrown into one very long, horizontally scrolling line.
You can see exactly what I'm talking about here:
https://zippy.gfycat.com/GenerousBigHerring.webm
How can I prevent this from happening? I've been screwing around with this for a while now. I've tried setting lines and maxLines, etc, but I can't figure it out.
Edit:
This is my current ScrollView/EditText:
<ScrollView
android:id="#+id/result_text_scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/result_title_text"
android:layout_above="#+id/result_bottom_sheet"
android:layout_marginTop="20dp"
android:padding="5dp">
<EditText
android:id="#+id/extracted_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:padding="15dp"
tools:text="Hello, World"
android:textColor="#color/black"
android:textStyle="bold"
android:textSize="#dimen/extracted_text_size"
android:textIsSelectable="true"
android:inputType="none"
/>
</ScrollView>
From code, here's what I'm doing to to enable/disable editing:
#Override
public void enableTextEditing() {
mExtractedText.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE);
mExtractedText.setOnKeyListener(this);
}
#Override
public void disableTextEditing() {
mExtractedText.setInputType(InputType.TYPE_NULL);
mExtractedText.setOnKeyListener(null);
}
#Override
public boolean onKey(View view, int i, KeyEvent keyEvent) {
if (keyEvent.getAction() == KeyEvent.ACTION_DOWN && keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
//All this does is call the View methods to disable text editing
//and close the keyboard.
mPresenter.doneEditingButtonPressed();
return true;
}
return false;
}
Add android:lines , android:minLines and android:maxLines to your EditText view
Also change android: inputType = "textMultiline"
You can add android:scrollbars="vertical" to your EditText as well if you wish
I was wondering if there is a way to group EditText in a way that you can only traverse among a group of them.
The problem is that I rely on reaching the end of the first group and use EditorInfo.IME_ACTION_DONE in order to trigger a certain action.
The inner group of EditTexts is inside a LinearLayout.
Put the text boxes in a layout(linear or relative) only those EditText which you want to make a group. layout will act as group. Add this on your every Edittext xml--
android:maxLines="1"
if it does not works the you can handle focus.
Focus Handling
Focus movement is based on an algorithm which finds the nearest neighbor in a given direction. In rare cases, the default algorithm may not match the intended behavior of the developer.
Change default behaviour of directional navigation by using following XML attributes:
android:nextFocusDown="#+id/.."
android:nextFocusLeft="#+id/.."
android:nextFocusRight="#+id/.."
android:nextFocusUp="#+id/.."
Besides directional navigation you can use tab navigation. For this you need to use
android:nextFocusForward="#+id/.."
To get a particular view to take focus, call
view.requestFocus()
To listen to certain changing focus events use a View.OnFocusChangeListener
Keyboard button
You can use android:imeOptions for handling that extra button on your keyboard.
Additional features you can enable in an IME associated with an editor to improve the integration with your application. The constants here correspond to those defined by imeOptions.
The constants of imeOptions includes a variety of actions and flags, see the link above for their values.
Value example
ActionNext :
the action key performs a "next" operation, taking the user to the next field that will accept text.
ActionDone :
the action key performs a "done" operation, typically meaning there is nothing more to input and the IME will be closed.
Code example:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="32dp"
android:layout_marginTop="16dp"
android:imeOptions="actionNext"
android:singleLine="true"
android:ems="10" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/editText1"
android:layout_below="#+id/editText1"
android:layout_marginTop="24dp"
android:imeOptions="actionDone"
android:singleLine="true"
android:ems="10" />
</RelativeLayout>
If you want to listen to imeoptions events use a TextView.OnEditorActionListener.
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
performSearch();
return true;
}
return false;
}
});
Edit:
For dynamic edittext you can try..
EditText etCurrent;
Set an OnTouchlistener on each EditText:
valueET.setOnTouchListener(new OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (etCurrent != null) {
if (etCurrent.getId() != v.getId()) {
if (!check(etCurrent.getId())) {
etCurrent.setSelection(0,
etCurrent.getText().toString().length());
return true;
} else {
etCurrent = (EditText) v;
}
}
} else {
etCurrent = (EditText) v;
}
}
return false;
}
});