first time,click an edittext in expandablelistview,the whole layout scrolled ,and user can see edittext. then click softkeyboard finish to collapse softkeyboard and click this e
By many days spent,I found a solution. It is a hack.
detect softkeyboard show by visiable layout change.
public final void setKeyboardListener(final OnKeyboardVisibilityListener listener) {
final View activityRootView = getWindow().getDecorView()
.findViewById(android.R.id.content);
activityRootView.getViewTreeObserver()
.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
private final Rect r = new Rect();
private boolean wasOpened;
@Override
public void onGlobalLayout() {
activityRootView.getWindowVisibleDisplayFrame(r);
int heightDiff = activityRootView.getRootView().getHeight()
- (r.bottom - r.top);
boolean isOpen = heightDiff > 100;
if (isOpen == wasOpened) {
return;
}
wasOpened = isOpen;
listener.onVisibilityChanged(isOpen);
}
});
}
public interface OnKeyboardVisibilityListener {
void onVisibilityChanged(boolean visible);
}
when the softkeyboard show,pick up a textview in listview item or expandablelistview child item. then set it text for any thing, the whole view scrolled as normal! code like this:
activity.setKeyboardListener(new OnKeyboardVisibilityListener() {
@Override
public void onVisibilityChanged(boolean visible) {
if (visible) {
Message message = new Message();
message.what = 999;
handler.sendMessage(message);
}
}
});
private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
if (msg.what == 999) {
if (mDataMap.size() > 0) {
for (int i = 0; i < expandablelistview.getChildCount(); i++) {
View v = expandablelistview.getChildAt(i);
TextView tvCannotSee = (TextView) v.findViewById(R.id.tv_cannot_see );
if (tvCannotSee != null) {
//this is the key hack to make adjuspan work! and scroll the whole view up as normal
tvCannotSee.setText("this is an android bug");
return;
}
}
}
return;
}
super.handleMessage(msg);
}
};
this textview show invisble to user for proper purpose.if it is a expandablelistview and the edittext in childitem,the textview update must be in a childitem.
I also faced the same issue, but after googling the issue for some time i ended up the problem as below.
1) Add android:windowSoftInputMode="adjustPan" tag inside activity of manifest file
<activity
android:name=".MainActivity"
android:configChanges="locale|keyboardHidden|orientation|screenSize|layoutDirection|screenLayout"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden|adjustResize|adjustPan"></activity>
2) add android:descendantFocusability="beforeDescendants" attribute to your expandable listview as below.
<ExpandableListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/textDate"
android:layout_below="@+id/relativeLayout2"
android:descendantFocusability="beforeDescendants"
android:layout_margin="@dimen/margin_meium"
android:groupIndicator="@android:color/transparent" />