I have a strange problem that I am having problems even with the wording.
My layout is a relative layout containing a scroll containing chips and editing text. Below the scrolling, a list opens for automatic completion, below which is a linear layout in which the editing text and button are located. (Screen shots at the end of this post).
When the fragment is loaded and the user enters into the edittext inside the scroll, a list appears with options for automatic completion. When the autocomplete option is selected, which is added as the selected chip. The library that generates these chips does not clear the focus of the edit text, but something runs around the OS to move the focus to the bottom text of the edit. This leads to a strange state where the REVERSE edit texts blink as if they were focused. If the user types again on the keyboard, the focus is on the lower text editor, and now it is impossible to focus again on the first text editor.
The code for NonFocusingScrollView as follows. This correctly fixed my problem when scrolling around the ChipsView captured the focus and prevented the text from being edited correctly. ( SevenChipsView in the layout is just an extension of ChipsView ).
I tried, programmatically, to remove the focus from the bottom text of the edit and explicitly put it back into the edit text in the scroll, but this does nothing.
Is there a way by which I can prevent the focus from shifting the OS and stay in the top text editor until the user removes the bottom text of the edit?
public class NonFocusingScrollView extends ScrollView {
public NonFocusingScrollView (Context context) {
super (context);
}
public NonFocusingScrollView (Context context, AttributeSet attrs) {
super (context, attrs);
}
public NonFocusingScrollView (Context context, AttributeSet attrs, int defStyleAttr) {
super (context, attrs, defStyleAttr);
}
@TargetApi (Build.VERSION_CODES.LOLLIPOP)
public NonFocusingScrollView (Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super (context, attrs, defStyleAttr, defStyleRes);
}
@Override
protected boolean onRequestFocusInDescendants (int direction, Rect previouslyFocusedRect) {
return true;
}
@Override
public ArrayList getFocusables (int direction) {
return new ArrayList ();
}
@Override
public void requestChildFocus (View child, View focused) {
// avoid scrolling to focused element all together
}
}
XML Layout
<?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" android:orientation="vertical"> <LinearLayout android:id="@+id/messaging_announcement_recipient_container" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="top" android:background="@color/screen_background" android:orientation="horizontal" android:padding="8dip"> <TextView style="@style/default_textview" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_marginEnd="8dip" android:layout_marginLeft="0dp" android:layout_marginRight="8dip" android:layout_marginStart="0dp" android:gravity="center_vertical" android:text="@string/recipient_to" android:textColor="@android:color/white" /> <com.sevenshifts.android.views.NonFocusingScrollView android:id="@+id/messaging_announcements_recipients_scroll_view" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="2" android:focusable="true" android:focusableInTouchMode="true" android:padding="0dp"> <com.sevenshifts.android.views.SevenChipsView android:id="@+id/messaging_announcements_recipients" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="0dp" android:textColor="@android:color/white" app:cv_bg_color_clicked="@color/primary" app:cv_color_clicked="@color/primary" app:cv_icon_placeholder="@drawable/ic_house" /> </com.sevenshifts.android.views.NonFocusingScrollView> </LinearLayout> <se.emilsjolander.stickylistheaders.StickyListHeadersListView android:id="@+id/messaging_announcements_recipient_autocomplete" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@+id/messaging_announcement_recipient_container" android:visibility="gone" /> <LinearLayout android:id="@+id/messaging_announcements_compose_post_container" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_marginLeft="8dip" android:layout_marginRight="8dip" android:minHeight="44dip" android:orientation="horizontal"> <EditText android:id="@+id/messaging_announcement_post_text" android:layout_width="0dip" android:layout_height="wrap_content" android:layout_weight="1" android:hint="@string/announcement_hint" android:inputType="textMultiLine|textCapSentences|textAutoCorrect" android:maxLines="5" /> <Button android:id="@+id/messaging_announcement_post_button" android:layout_width="80dp" android:layout_height="44dip" android:background="@null" android:text="@string/send" android:textColor="@color/primary" /> </LinearLayout> <include layout="@layout/component_loading" /> </RelativeLayout>
There is a stream of screenshots in this imgur gallery - there are too many not to crowd this message: http://imgur.com/a/zWY0D