focus is not shifting to next edittext automatically? - android

I am trying to add and remove edittext through RecyclerView Adapter and it's working fine but I also want to shift the focus to next empty edittext when I click on adapter item which fills the edit text. It would be grateful if someone could help ,I am newbie to android.
Here is my focus next method:
private void focusNext() {
View view = getAdapterView(mAddDropPointAdapter.getCurrentFocusedPosition() + 1);
}
if (view != null) {
view.findViewById(R.id.fragment_google_autoc_et_destination).requestFocus();
} else if (getActivity() != null) {
KeyboardUtils.hideKeyboard(getActivity());
}
}
Here is from where I am calling this method.
#Override
public void onAdapterItemClick(int position, #NonNull GoogleAutoCompleteAddressDto addressDto) {
/// Doing some stuff
focusNext();
}
After clicking the adapter item , focus stays at the same edittext it doesn't shift to next.

Related

Edit text loosing focus after typing something

I am inflating edit text in adapter class within of a list view. View is looking cool multiple edit text are appearing properly but when I do focus on the edit text or if I try to type something it loosing focus I tried to adding listeners, changing manifest file but nothing works for me.
following code is not working for me
#Override
public View getChildView(int position, int i1, boolean b, View view,
ViewGroup viewGroup) {
EditText comment = view.findViewById(R.id.txtRecordComment);
comment.setOnFocusChangeListener(new OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
handler.postDelayed(new Runnable() {
#Override
public void run() {
if (lastFocussedPosition == -1 || lastFocussedPosition == position) {
lastFocussedPosition = position;
edittext.requestFocus();
}
}
}, 200);
} else {
lastFocussedPosition = -1;
}
}
});
return view;
}
please help me to resolve this issue
Since you are using a ListView, it is bound to happen with your current code implementation.
You must remember that if your EditText is in a ListView, every key down will result in the edit text losing and getting focus because all the views are redrawn, so the edit text representing whatever row used to be focused is now a completely different object.
To get the expected behaviour, declare a variable in your adapter: int focusedRow. In getView method of your adapter, add an onFocusChanged listener to the EditText and when that edit text gains focus, set focusedRow = whatever row the focused EditText happens to be in.
Also set any edit text that is in the currentlyFocusedRow to be focused.
Update:
If you have multiple EditTexts, add an onFocusChanged listener to each edit text.
Add below code in Android Manifest file
<activity android:name=".ActivityName"
android:label="#string/app_name"
android:windowSoftInputMode="adjustPan">
Hope this will work

How to properly get & set text to editText in expandable recycler view

i'm working with expandable recycler view from bignerdranch. Inside my child view, i placed a edit text where user can leave a comment regarding an issue shown on the parent view.
My problem is that, i wanted the user input to be save after the edit text loose focus. (In this case, i have 3 parents, and each parent has 1 editText). But when i input edit text 1 and focus on edit text 2 without inputing... edit text 2 would take up edit text 1 input after it loose focus.
I try using text watcher, and put the codes inside after text changes.. but the app freezes and stopped working after a while. If there a better way for me to save accordingly?
mCatatan is my editText.
#Override
public void onBindChildViewHolder(final ATPChildViewHolder atpChildViewHolder, int i, Object childObject) {
final ATPChild atpChild = (ATPChild) childObject;
final String text = atpChildViewHolder.mCatatanInput.getText().toString();
if(!text.equals("")) {
atpChild.setDetail(text);
atpChildViewHolder.mCatatanInput.setText(atpChild.getDetail());
} else {
atpChildViewHolder.mCatatanInput.setText(atpChild.getDetail());
}
// todo: fixed catatan being saved to another catatan
atpChildViewHolder.mCatatanInput.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus) {
Log.d(TAG, "onFocusChange: ");
atpChild.setDetail(atpChildViewHolder.mCatatanInput.getText().toString());
atpChildViewHolder.mCatatanInput.setText(atpChild.getDetail());
}
}
});
}

Page focus scrolls back to AutoCompleteTextView

Have an autocomplete textView in layout which is in a ScrollView.
mAutoCompleteTextView.addTextChangedListener(new TextValidator(mAutoCompleteTextView) {
#Override
public void validate(TextView textView, String text) {
if(text == null){
mAutoCompleteTextView.setError(text);
}
});
This shows a red error icon with a dropdown error message in case text is not valid. While error is visible and page is scrolled, the centre of page returns back to this view instead of scrolling up/down.
How to avoid this while error is still visible?
Try this ..
This will allow you to scroll smoothly, if setEnabled() doesnt work you can also user clearFocus() and requestFocus()
scrollLayout.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
#Override
public void onScrollChanged() {
Rect rect = new Rect();
mAutoCompleteTextView.setEnabled(false);
if (mAutoCompleteTextView.getGlobalVisibleRect(rect)
&& mAutoCompleteTextView.getHeight() == rect.height()
&& mAutoCompleteTextView.getWidth() == rect.width() && mAutoCompleteTextView.isShown()) {
mAutoCompleteTextView.setEnabled(true);
} else {
mAutoCompleteTextView.setEnabled(false);
}
}
});
Hope this helps
In the root Layout use this :
android:descendantFocusability="beforeDescendants"
And then in onCreate():
rootLayout.requestFocus();
Hope this helps.

swipelayout working but no feed

I am using swipelayout from daimajia.I get some data from services.When the service has a date than will visible an icon that will open the left sideBut it do nothing when clicking the icon.I have no error that's the reason why cannot resolve it.The action is when clicking the icon,that visible a textview and start a chronometer.
Here is my swipeListener
private SwipeListener swipeListener = new SwipeListener() {
#Override
public void onStartOpen(SwipeLayout layout, SwipeLayout.DragEdge edge) {
if (edge == SwipeLayout.DragEdge.Left && viewHolder.discountText != null) {
**viewHolder.discountText.setTimeByTag().play();**
LogUtils.LogE("Left Open...");
}
}
#Override
public void onOpen(SwipeLayout layout, SwipeLayout.DragEdge edge) {
super.onOpen(layout, edge);
if (edge == SwipeLayout.DragEdge.Left && viewHolder.discountText != null) {
viewHolder.discountText.setTimeByTag().play();
LogUtils.LogE("Left Open...");
}
}
#Override
public void onClose(SwipeLayout layout, SwipeLayout.DragEdge edge) {
if (edge == SwipeLayout.DragEdge.Left && viewHolder.discountText != null) {
viewHolder.discountText.stop();
LogUtils.LogE("Left Close!");
}
}
};
public void openLeft() {
LogUtils.LogE("onClick openLeft-");
if (getSwipeLayout() == null){
LogUtils.LogE("onClick -null-");
return;
}
if (!getSwipeLayout().isOpen()) {
getSwipeLayout().open(true, SwipeLayout.DragEdge.Left);
LogUtils.LogE("onClick --");
}
}
all the codes working in other my fragments.I need some idea what's the reason that it not give true action that swipe to left.
EDIT:
Here is the Logs:
In this picture I have 2 items there which it's in my favorite page.The last one item has end date that will be visible the icon(ImageView).When pressing the icon,it should swipe to left side but it's not working and give the result like this picture which I'm shared.
EDIT
There is something more.I had looked the codes in debug mode and give here an message:
but put define swipeLayout into my code:
sl.setShowMode(SwipeLayout.ShowMode.LayDown);
sl.setDragEdges(SwipeLayout.DragEdge.Left, SwipeLayout.DragEdge.Right);
sl.setBottomViewIds(R.id.productBottomLeft, R.id.productBottomRight, SwipeLayout.EMPTY_LAYOUT, SwipeLayout.EMPTY_LAYOUT);
TextView button = SwipeLayout.findViewById(R.id.yourButtonId) //the bottom view;
button.setOnClickListener(v -> yourMethod());

Show AutoCompleteTextView Popup always above of TextField

I am trying to develop small app in which i used AutoCompleteTextView and i used
simpleCursorAdapter.setFilterQueryProvider(new FilterQueryProvider() {
// my stub here
}
As my filtration goes specific ,my Dropdown(Anchor) goes beneath of Virtual keyboard. That means supppose that first i search with
DR. then it shows list of 15 doctor in Dropdown(Anchor) with no any problem. But as i typed DR.Kum , now Dropdown(Anchor) have only one name so that Dropdown(Anchor) goes down of virtual keyboard . When it has 15 name of list it showing perfectly.How to show Dropdown(Anchor) always above of AutoCompleteTextView.??
I solved this problem by one trick
// It will capture number item in your DropDown . If number of item in drop is 2
// or 1 , then hide keyboard.
if(cur_hide_keyboard.getCount() ==2 || cur_hide_keyboard.getCount() ==1){
hideKeyBoard();
}
private void hideKeyBoard() {
InputMethodManager imm = (InputMethodManager) activity
.getSystemService(Activity.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(doctorsName.getWindowToken(), 0);
}
Create a subclass of your anchor. In most cases, the anchor is AutoCompleteTextView.
Override the getWindowVisibleDisplayFrame method in this way, for example:
class AutoCompleteTextViewImpl extends android.support.v7.widget.AppCompatAutoCompleteTextView {
private boolean mShowDropDownAlwaysAbove;
public AutoCompleteTextViewImpl(Context context) {
super(context);
}
public void setShowDropDownAlwaysAbove(boolean showAbove) {
mShowDropDownAlwaysAbove = showAbove;
}
#Override
public void getWindowVisibleDisplayFrame(Rect outRect) {
super.getWindowVisibleDisplayFrame(outRect);
if (mShowDropDownAlwaysAbove)
outRect.bottom = -3000; // hack for https://github.com/AndroidSDKSources/android-sdk-sources-for-api-level-23/blob/master/android/widget/PopupWindow.java#L1449
}
}
Now dropDown will always show above.
The reason is hidden in this portion of the code responsible for calculating the top coordinate.

Categories

Resources