Keyboard placement obscures view below EditText would like to keep visible - android

I have an activity that is basically a long form of entry fields.
On each row, I want to show a TextView to serve as hint text just below each EditText and I want the TextView to remain visible at all times when the user is entering data. Unfortunately, the soft keyboard obscures the hint text and always positions itself immediately below the EditText. Is there any technique that will allow the TextView below the EditText to also be visible when the soft keyboard appears and the contents are adjusted (via windowSoftInputMode=adjustResize|adjustPan), without having the user scroll ?

Vishavjeet got me on the right track in suggesting I scrolldown to reveal the view that may be overlapped by the keyboard. Below is a function similar to what I used to solve the problem. It can be called when the EditText above the TextView receives focus:
// View targetView; // View that may be hidden by keyboard
// ScrollView scrollContainerView; // Scrollview containing hiddenView
//
void assureViewVisible (View targetView, ScrollView, scrollContainerView) {
Window rootWindow = activity.getWindow();
Rect rMyView = new Rect();
View rootview = rootWindow.getDecorView();
rootview.getWindowVisibleDisplayFrame(rMyView); // Area not taken up by keyboard
int subTextPos[] = new int[2];
targetView.getLocationInWindow(subTextPos); // Get position of targetView
int subTextHt = targetView.getHeight(); // Get bottom of target view
if ((subTextPos[1]+subTextHt) > rMyView.bottom) { // Is targetView at all obscured?
int scrollBy = (subTextPos[1]+subTextHt) - rMyView.bottom + 10; // add a small bottom margin
mMeasurementViewScrollView.smoothScrollBy(0, scrollBy); // Scroll to subtext
}
}

EDIT:
By understanding the problem more deeply, I think that you should add scroll programatically when user clicks on the Edittext. Here is the code to do that:
private final void focusOnView()
{
new Handler().post(new Runnable()
{
#Override
public void run()
{
your_scrollview.scrollTo(0, your_EditBox.getBottom());
}});
}
From my personal experience I think there is not such way to do that. The thing you can do is place the hint textview toRightOf the editext. Or Use modern Approach by using a Hint Placeholder on Edittext:
In XML, it's simply android:hint="someText"
Programatically you can use edittext.setHint(int);
pass R.string.somestring in above method.

Related

I need to make a box in andengine

protected void texto() {
activity.runOnUiThread(new Runnable() {
public void run() {
final EditText input = new EditText(activity);
String value = input.getText().toString().trim();
input.setInputType(InputType.TYPE_CLASS_TEXT);
}
});
}
Doesn´t show me the text box on the scene maybe someone knows I'm doing wrong.
You need to at it to your View. Right now you are instantiating an EditText view but is not added to the layout View (LinearLayout, RelativeLayout, etc.) that your screen is rendering, thus making it not appearing.
To solve it, first you need to get your View using activity.findViewById, then you add the EditText view as a subview to it.
Adjust the position if needed.

Update parent of TextSwitcher when text changed

Im using a textSwither for hide/show a part of text like this way :
txtDescription.setInAnimation(in);
txtDescription.setOutAnimation(out);
txtDescription.setFactory(new ViewSwitcher.ViewFactory() {
#Override
public View makeView() {
TextView textView = new TextView(ShopContentDetailActivity.this);
textView.setTextColor(getResources().getColor(R.color.NightDark));
return textView;
}
});
And call this method for change text :
private void changeDescription() {
if (displayShort)
txtDescription.setText(Html.fromHtml(shortDescription));
else txtDescription.setText(fullDescription);
displayShort = !displayShort;
}
My problem is when user touch textSwitcher to display text and touch again to hide it ,the height of parent view (a linear layout ) of textSwitcher remain as when text is displayed and dont change its height.
How can i update the parent view when text change ? (its ok when touch for display full text)
I resolve my problem in this way : (I think TextSwutcher change visibility of TextViews to INVISIBLE not GONE then i use this trck)
private void changeDescription() {
if (displayShort) {
txtDescription.setCurrentText(null); // this line change invisible textView visible but without text and make it height 0 and then set the second textView text
txtDescription.setText(Html.fromHtml(shortDescription));
} else txtDescription.setText(shopContent.getDescription());
displayShort = !displayShort;
}
But there is a problem that is not so important for my case: when you hide a part of text its blink.
if i resolve it i will update my answer.

Can't edit an edittext in a popup window without dismissing and recalling it first

I am using a popup window to display some information and have an edit button that allows that information to be changed. I am loading all textviews, buttons and edittext fields and hiding/showing them as needed. The edittext fields are not letting me edit them. I have tried the below suggestion about setting focusable to true, but that isn't working. Any other suggestions?
Tried this: EditText On A Popup Window
EDIT: Below is part of my code. I've just included the parts for initializing the edittext and showing the popup contents since everything else is working, just not the edittext. I am using a tablelayout, and when the user clicks a row, the popup window displays. Keep in mind I'm still pretty new to Java and Android!
EDIT #2: The softkeyboard was not showing when the edittext was selected, but now it will show if I dismiss the popup once and then call it again. I then tried forcing the softkeyboard to display, and it showed behind the popup (another problem). I was able to select the number 1 since it was barely showing behind the popup window, but it didn't seem to work either. The fix was the same here: dismiss the popup window and recall it. So my remaining problem is being able to type into the edittext without having to dismiss the popup once and recall it. As such, I am changing the title of this question.
row1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
final EditText pwETBrand = (EditText) vPopUp.findViewById(R.id.et_editbrand);
if (!infoClick) {
infoClick = true;
// Popup elements initialized earlier
pwInfo.showAtLocation(llInfo, Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL, 0, 0);
pwInfo.update(0, 0, llMain.getWidth()-50, llMain.getHeight()-100);
pwInfo.setFocusable(true);
....
// Hide some elements initially until "EDIT" button is pressed
pwETBrand.setVisibility(View.INVISIBLE);
....
// When EDIT button is pressed, hide default elements, and show edit elements
pwEdit.setOnClickListener(new OnClickListener() {
public void onClick(View v2) {
pwETBrand.setVisivility(View.VISIBLE);
// Other element settings go here
pwInfo.setFocusable(true);
}
)};
....
}
}
I have implemented a solution, though it may not be the best solution. I have set a boolean field at the class initialization that checks if the popupwindow has ever been called. If it has not yet been called, then it will immediately dismiss the popupwindow and re-open it since my problem is in the popupwindow initialization.
pwInfo.showAtLocation(llInfo, Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL, 0, 0);
pwInfo.update(0, 0, llMain.getWidth()-50, llMain.getHeight()-100);
pwInfo.setFocusable(true);
if (pwFirst) {
pwFirst = false;
pwInfo.dismiss();
pwInfo.showAtLocation(llInfo, Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL, 0, 0);
pwInfo.update(0, 0, llMain.getWidth()-50, llMain.getHeight()-100);
pwInfo.setFocusable(true);
}
Not the best solution, but it works.
Try this,
final PopupWindow popupWindow = new PopupWindow(popupView,LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,true);
works for me.
Use Below Link's Code for that, it may help you.
Popup With Edittext
Whenever you create a PopupWindow you must put true in focusable like that :
PopupWindow(View contentView, int width, int height, boolean focusable)
final PopupWindow popupWindow = new PopupWindow(popupView,LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT,true);
good luck

Popup Keyboard issue in android, when column limits are specified

Im working on an input method for android and one of the tasks is to implement a custom popup keyboard for hard keyboard key presses. Usually input methods let the editor handle that but the thing is I need to add more symbols than android supports.
So I implemented the popup keyboard and even have it displaying well when a hard key (character key) is long pressed.
The steps I've followed are:
Create popup window.
Inflate a linear layout which contains a keyboardview and a close button and save it to a view object
bind the keyboardview and close buttons to the relevant objects
Create a keyboard for the popup characters and set it as the keyboard for the keyboard view. The keyboard has a column limit of 5.
set the linear layout as the content view for the popup window
Display the popup window
THE ISSUE: If there are multiple rows in the popup keyboard I am only able to select key in the last row for the column. Even if I click on the key in the first row of that column, the key in the last row gets selected.
If anyone could explain why this is happening and how do I fix it, Id appreciate it.
THE CODE:
PopupWindow mPopupKeyboard = new PopupWindow(this.getBaseContext());
mPopupKeyboard.setBackgroundDrawable(null);
if(mPopupKeyboard != null)
{
this.dismissPopupKeyboard();
View mMiniKeyboardContainer = null;
KeyboardView mMiniKeyboard = null;
View closeButton = null;
mMiniKeyboardContainer = getLayoutInflater().inflate(R.layout.keyboard_popup_keyboard, null);
mMiniKeyboard = (KeyboardView) mMiniKeyboardContainer.findViewById(R.id.popup_keyboardView);
closeButton = mMiniKeyboardContainer.findViewById(R.id.closeButton);
if (closeButton != null)
{
closeButton.setOnClickListener(new OnClickListener()
{
#Override
public void onClick(View arg0)
{
mPopupKeyboard.dismiss();
});
}
mMiniKeyboard.setOnKeyboardActionListener(this);
String resourcestring = "abcdefghi";
mMiniKeyboard.setKeyboard(new Keyboard(this.getBaseContext(), R.xml.kbd_popup_template, alternates, 3, 0));
mMiniKeyboard.setPopupParent(mCandidateView);
mPopupKeyboard.setContentView(mMiniKeyboardContainer);
mPopupKeyboard.setWidth(LayoutParams.WRAP_CONTENT);
mPopupKeyboard.setHeight(LayoutParams.WRAP_CONTENT);
mPopupKeyboard.showAtLocation(mCandidateView, Gravity.TOP, 0, 0);
}
I had a similar problem with popup keyboards. I found that it was a problem only with Android 2.3. My only workaround was to avoid popup keyboards with more than one row.
The reason this occurs is because KeyboardView sends off the MotionEvent. MotionEvent.getRawX() and getRawY() only return coordinates within the bounds of KeyboardView. If the MotionEvent happens above KeyboardView, it returns the closest absolute coordinates in KeyboardView.
One solution is to create an invisible View above KeyboardView. It will have to detect the MotionEvent and then pass the MotionEvent back to KeyboardView and then your multirow popup keyboard will work
For the starting code look at CandidateViews above the KeyboardView. For example look at this project:
https://github.com/blackcj/AndroidCustomKeyboard
In the
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
(https://github.com/blackcj/AndroidCustomKeyboard/blob/master/app/src/main/java/com/blackcj/customkeyboard/CandidateView.java)
method add 200 to desiredHeight in this statement:
setMeasuredDimension(measuredWidth, resolveSize(desiredHeight, heightMeasureSpec));
Notice how this will cause the motionEvent.getRawY() to work for an extra 200p in height

Defining EditText imeOptions when using InputMethodManager.showSoftInput(View, int, ResultReceiver)

In my application I have a custom view which requires some text input. As the view in itself doesn't contain any actual views (it's a Surface with custom drawing being done), I have a FrameLayout which contains the custom view and underneath it an EditText -view. When the user does a specific action, the custom view is hidden and the EditText takes over for user input. This works fine, but android:imeOptions seem to be ignored for this view. I'm currently doing this:
InputMethodManager inputMethodManager = (InputMethodManager)parent.getSystemService(Context.INPUT_METHOD_SERVICE);
EditText t = (EditText)parent.findViewById(R.id.DummyEditor);
t.setImeOptions(EditorInfo.IME_ACTION_DONE);
inputMethodManager.showSoftInput(t, 0, new ResultReceiver(mHandler) {
#Override
protected void onReceiveResult(
int resultCode, Bundle resultData) {
// We're done
System.out.println("Editing done : " +
((EditText)parent.findViewById(R.id.DummyEditor)).getText());
}
}
);
It seems that the setImeOptions(EditorInfo.IME_ACTION_DONE) has no effect. I've also tried adding the option to the layout XML with android:imeOptions="actionDone". No help.
Any ideas?
this post looks like will answer your question:
How do I handle ImeOptions' done button click?

Categories

Resources