What i have to do:
I'm implementing some kind of fancy calculator for special measurements. For this, i have a ListView with sever edit texts.
Per row are tow EditTexts where the user shall be able to enter decimal values.
What my problem is:
I have set inputType both in code and xml, but i get weird behavior out of this. After tapping any number, the normal keyboard pops up for like half a second, then switching back to the decimal keyboard.
I guess the problem comes from me calling requestFocus() on the currently active EditText. But in the way my Calculator needs to work, i have to do this, since every change from the user results in a recalculation of my values (therefore, updating the whole list view --> results in loss of focus which shall be prevented)
Important Code Snippets so far:
<EditText
android:id="#+id/TextValue"
android:layout_width="100dp"
android:layout_height="30dp"
android:layout_weight="0.45"
android:background="#E6E6E6"
android:inputType="numberDecimal"
android:hint="#string/Ung"
android:textAlignment="viewEnd"
android:layout_gravity="end"
android:paddingRight="5dp"
/>
(Same code for second EditText in row)
RequestFocus is called in the getView method of my ArrayAdapter, since Reloading --> Loss of Focus --> ...
....
if (position == currentTag) {
textValue.requestFocus();
}
....
Related
Try stacking two fragments with editTexts on top of each other using an Add Transaction. after that when you press the keyboard imeOption key next button the bottom fragment's edit text can gain focus. this is a security concern. user can type things into the bottom fragments edit text (blindly). I tried the following code:
android:filterTouchesWhenObscured="true"
but it has not helped at least on api 27.
my edit text itself looks like this, nothing special:
<EditText
android:id="#+id/et"
android:layout_width="195dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:imeOptions="actionNone"
android:layout_marginBottom="10dp"
android:hint="#string/enter_name"
android:filterTouchesWhenObscured="true"
android:inputType="textNoSuggestions"
android:textColorHint="#959595"
android:textSize="11sp" />
the issue is very similar to android tap jacking
i tried even doing this:
android:nextFocusDown="#+id/et_two" thinking it would bypass and go directly to the edittext i want. but instead the bottom edit text still gains focus.
the issue solution was surprising. recyclerview was stealing focus. see this SO incident:
adding android:descendantFocusability="blocksDescendants" to the recyclerview stopped the issue.
I have an editText that I want to fill in automatically with info from other controls in the form, and at the same time allow to change its contents, discouraging the user from doing so though.
So I set this control to not focusable so when you press actionNext it moves on to the next control. However if you click the edit text, I want to allow the user to change its contents.
This is what I did:
mNameEditText.setFocusable(false);
mNameEditText.setFocusableInTouchMode(false);
mNameEditText.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mNameEditText.setFocusableInTouchMode(true);
mNameEditText.requestFocusFromTouch();
mNameEditText.setFocusable(true);
}
});
However this behaves very weirdly, the result is that when you click, you can edit, but suddenly the next control (an AutoCompleteTextView) is not focusable anymore! Actually it looks like the focus remains on the edit text and goes to the autocompletetextview at the same time, like so:
How can I fix this?
Make a sub class of your text edit view
Use it in your view
Set its enabled property to false
Overwrite the touch handlers within your subclass: when the text edit view is touched, enable the view now and focus it. When the focus is lost, disable the text edit view again. Do all that in the subclass.
Style the text edit view properly so that the user has the impression that it's editable
If you want the automatic focus change to skip some views, you can use a combination of the nextFocus* attributes.
Something like :
<EditText
android:id="#+id/txt1"
android:imeOptions="actionNext"
android:nextFocusForward="#+id/txt3"
android:nextFocusDown="#+id/txt3"
... />
<!-- skipped view -->
<EditText
android:id="#+id/txt2"
android:imeOptions="actionNext"
... />
<EditText
android:id="#+id/txt3"
android:imeOptions="actionNext"
android:nextFocusUp="#id/txt1"
... />
nextFocusForward is the one used for actionNext. I believe the other attributes are mostly useful in non touch mode (e.g. with a hardware keyboard)
I'd like to do textual back-and-forth interaction in an Android control. The idea is to have something like this:
This is some text output by the program.
What is your name? |
with the cursor at | (note that editing doesn't start at the beginning of the last line). The user is then free to enter text (using whatever Android input method, keyboard, etc.) but isn't allowed to change any of the output so far. Ideally, the user's input would be styled differently.
Then, as soon as newline is entered, I want the program to be notified and editing to stopped:
This is some text output by the program.
What is your name? Foo Bar
Hello, Foo Bar!
Note that this needs to be a proper control, i.e. one I can compose with other controls to make it just one part of the app's main layout.
Make a TextView and the EditText next to each other then your problem is solved and add the following line of code in EditText.
android:singleLine= 'true';
It allow only one line to be entered to the EditText. let me know whether this is what your expecting.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="What is your Name?"
android:id="#+id/textView"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:id="#+id/editText"
android:layout_alignParentTop="true"
android:layout_toEndOf="#+id/textView" />
</RelativeLayout>
This is some text output by the program.
What is your name? |
with the cursor at | (note that editing doesn't start at the beginning
of the last line). The user is then free to enter text (using whatever
Android input method, keyboard, etc.) but isn't allowed to change any
of the output so far. Ideally, the user's input would be styled
differently.
I would strongly recommend to rethink about your design as the same thing can be done with the help of LinearLayout,Editext,TextView with very simple and more manageable way.
I would suggest you to create a new LinearLayout(TextView + EditText) and assign the background of layout like EditText and edittext's no background.
Upon editText done, you could show a new TextView in the bottom
You need a ListView at top, to show your conversation & then below it, needs a horizontal view with a TextView (to show question) and EditText(with background transparent - to ask user to fill an answer).
I'm not looking for code, either I won't post any, just an explanation, because I'm kind of lost.
There is this main issue about the resizing when softkeyboard appear.
In my case
I have a listView feeded with 2 editText and many textView with database content using a custom cursorAdapter.
1) AdjustPan
It's pretty simple. When I use the adjustPan property, everything works quite good, except the fact that when I press an editText in my listView and if the listview is bigger than the screensize, I can't scroll. This is actually the normal behaviour and I can understand it.
2) AdjustResize
Here I can scroll as much as I wish.
This property is the one I want to use. But I'm facing 2 issues :
When I press on one of the two editText, I just can't write in. Impossible, even thought it has the focus. I'm forcing the softkeyboard to appear, I try to type some letters in (remember that this editText is focused) but nothing happens.
Again, when I press one of the two editText, it just reorganize (apparently randomly) listview's items. Even thought it's working perfectly with adjustPan, with adjustResize, it's messing with items of the listView.
Any information about one of the 2 issues would be helpful. You can even ask for code, but one more time, I'm just looking for a general explanation that could help. Thanks.
Here this mention issue is same facing me in my app and here some change in my code is this working fine in my app. please try this...
<activity android:name="com.MainActivity"
android:configChanges="orientation|screenSize"/>
<ListView
android:id="#+id/fields_list_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:descendantFocusability="afterDescendants"
android:focusableInTouchMode="true"
android:focusable="true"
/>
<EditText
android:id="#+id/input_edit_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:cursorVisible="true"
android:gravity="top"
android:inputType="none"
android:textColor="#color/black"/>
I'm writing a simple caesar-encryption-activity. Two EditTexts on screen, one clear-text, one crypted. Here's an example for the crypted EditText - the cleartext one is similar.
<EditText
android:layout_below="#id/Caesar_Label_CryptText"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="#+id/Caesar_Text_CryptText"
android:hint="Enter crypted text"
android:maxLines="2"
android:lines="2"
android:minLines="2"
android:inputType="text|textMultiLine|textVisiblePassword"
android:scrollbars="vertical"
android:gravity="top" />
Now when entering cleartext I have an TextChangedListener running that programatically crypts and fills that crypto-EditText. So far, so good.
When the cleartext entered gets really long, the cleartext-EditText scrolls with my imput, but the crypto-EditText stays at the top of the text. I'd really like the crypto-EditText to scroll so that it always shows the bottom line of its content.
How can that be done, preferably from the onTextChanged()-Method of the TextWatcher?
Ok, found it. It was the cursor (called Selection on EditText and TextViews).
This is how I got it to work:
ivClear // assigned the EditText that has the input
ivCrypt // assigned the target EditText, that I want to scroll
aText // the input from ivClear, crypted
Then use:
ivCrypt.setText(aText); // assign the Text
ivCrypt.setSelection(ivClear.getSelectionStart()); // scroll
Phew, finally :) Always underestimated the power of the Spannable ;)
The base class android.view.View has methods getScrollX(), getScrollY() and scrollTo() that may be helpful, though I haven't tried it.
http://developer.android.com/reference/android/view/View.html#scrollTo(int, int)