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.
Related
EditText as ChangeContact
EditText focus is not working in android studio, i want to hide a textview when focus change in edittext, how to do this?
ChangeContact.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus) {
Toast.makeText(mContext, "focus loosed", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(mContext, "focused", Toast.LENGTH_LONG).show();
bookLinear.setVisibility(View.GONE);
}
}
});
My edit text in XMl file
<EditText
android:id="#+id/etChangeAddress"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="6dp"
android:layout_marginBottom="8dp"
android:background="#drawable/shape_transparent"
android:ems="10"
android:focusable="true"
android:focusableInTouchMode="true"
android:gravity="center"
android:hint="Address"
android:inputType="textPersonName"
android:padding="5dp"
app:layout_constraintBottom_toTopOf="#+id/etChangeNumber"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
But i cant see the Toast
Please help ....
Have you tried with this for ChangeContact?
android:focusable="true"
android:focusableInTouchMode="true"
also
ChangeContact.requestFocus() ?
In my case I can't get on focus change event because I forgot to delete setContentView() function and used it with binding initialization like this:
setContentView(R.layout.activity_main)
binding = ActivityMainBinding.inflate(layoutInflater, null, false)
also eventually I understood that binding initialization also was incorrect
I am building a password visibility toggle system (Without using TextInputLayout).
It is working, but I wan to change the icon when user clicks on the icon inside the EditText input field.
xml
<EditText
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="#+id/etPassword"
android:layout_marginRight="20dp"
android:inputType="textPassword"
android:layout_marginLeft="20dp"
android:layout_marginBottom="20dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:background="#drawable/input_border"
android:drawableRight="#drawable/eye_image"
android:hint="Your Password" />
eye_image.xml
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:drawable="#drawable/eye_show"
android:width="25dp"
android:height="25dp"
/>
</layer-list>
java code
password.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
final int DRAWABLE_LEFT = 0;
final int DRAWABLE_TOP = 1;
final int DRAWABLE_RIGHT = 2;
final int DRAWABLE_BOTTOM = 3;
if(event.getAction() == MotionEvent.ACTION_UP) {
if(event.getRawX() >= (password.getRight() - password.getCompoundDrawables()
[DRAWABLE_RIGHT].getBounds().width())) {
// your action here
if(password.getTransformationMethod().equals(PasswordTransformationMethod.getInstance())){
//Show Password
((ImageView)(view)).setImageResource(R.drawable.eye_show);
password.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
password.setSelection(password.getText().length());
}
else{
//Hide Password
((ImageView)(view)).setImageResource(R.drawable.eye_show);
password.setTransformationMethod(PasswordTransformationMethod.getInstance());
password.setSelection(password.getText().length());
}
}
}
return false;
}
});
I get this error - androidx.appcompat.widget.AppCompatEditText cannot be cast to android.widget.ImageView
I just want to make the image in the eye_image.xml drawable which is placed at the right of the editText to change to another image onClick
Found a way, This did the trick
editText.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.eye_image2, 0);
So I have a problem on my Oneplus 3t that the enter key creates a new line and doesn't actually do action, but on Samsung phones it works fine. This is the EditText
<EditText
android:id="#+id/section"
android:layout_width="230dp"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="30dp"
android:layout_toEndOf="#+id/nav_button"
android:layout_toRightOf="#+id/nav_button"
android:background="#android:color/transparent"
android:clickable="false"
android:ems="10"
android:focusable="false"
android:gravity="left"
android:inputType="textMultiLine|textNoSuggestions"
android:maxHeight="140dp"
android:scrollbars="vertical"
android:text="#string/section"
android:textColor="#color/textColor"
android:textSize="20sp" />
And this is how I handle the action
mSearch.setOnKeyListener(new View.OnKeyListener() {
#Override
public boolean onKey(View view, int i, KeyEvent keyEvent) {
if (keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
switch (i) {
case KeyEvent.KEYCODE_DPAD_CENTER:
case KeyEvent.KEYCODE_ENTER:
unReadySeach(section, mSearch, search, mSearch.getText().toString(), mNavButton, backArrow);
gridView.setAdapter(new QuoteImageAdapater(getApplicationContext(), reader.getSearchData(mSearch.getText().toString()), section));
searched = true;
return true;
}
}
return false;
}
});
Also in the virtual device on a pixel 2, when I press on the enter key on the keyboard itself it creates a new line but when I press on enter key on my own keyboard of my pc it does work.
Edit: I fixed it by changing the EditText to this
<EditText
android:id="#+id/searchText"
android:layout_width="230dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/section"
android:layout_alignBottom="#+id/section"
android:layout_alignStart="#+id/section"
android:background="#drawable/underline"
android:ems="10"
android:hint="Search"
android:imeOptions="actionSearch"
android:inputType="textNoSuggestions|text"
android:maxHeight="140dp"
android:textColor="#color/textColor"
android:textColorHint="#color/textHint"
android:textCursorDrawable="#null"
android:textSize="20sp"
android:visibility="invisible" />
Try this one because solution you have used, it is not guaranteed for soft keys.
First Solution:
<EditText
android:id="#+id/search"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="#string/search_hint"
android:inputType="text"
android:imeOptions="actionSend" />
EditText editText = (EditText) findViewById(R.id.search);
editText.setOnEditorActionListener(new OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
boolean handled = false;
if (actionId == EditorInfo.IME_ACTION_SEND) {
sendMessage();
handled = true;
}
return handled;
}
});
Second Solution
mSearch.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
// If the event is a key-down event on the "enter" button
if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
(keyCode == KeyEvent.KEYCODE_ENTER))
{
// Perform action on Enter key press
unReadySeach(section, mSearch, search, mSearch.getText().toString(), mNavButton, backArrow);
gridView.setAdapter(new QuoteImageAdapater(getApplicationContext(), reader.getSearchData(mSearch.getText().toString()), section));
searched = true;
return true;
}
return false;
}
});
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
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;
}
});