Android 如何关注添加到ExpandableListView的新子项
我有和ExpandableListView,当在最后一个项目上按return键时,我会动态地添加子项目。当屏幕空间不足时,会添加我的新项目,但它不会被聚焦,也看不见b/c键盘可见。我想向下滚动,使最后一项成为焦点 在阅读了几篇文章并尝试了几条分享的想法后,我找到了解决问题的方法 在扩展了我在getChildView()中添加的BaseExpandableListAdapter的ExpandableListAdapter中,如下所示:Android 如何关注添加到ExpandableListView的新子项,android,expandablelistview,Android,Expandablelistview,我有和ExpandableListView,当在最后一个项目上按return键时,我会动态地添加子项目。当屏幕空间不足时,会添加我的新项目,但它不会被聚焦,也看不见b/c键盘可见。我想向下滚动,使最后一项成为焦点 在阅读了几篇文章并尝试了几条分享的想法后,我找到了解决问题的方法 在扩展了我在getChildView()中添加的BaseExpandableListAdapter的ExpandableListAdapter中,如下所示: //this line is added after I ad
//this line is added after I add the new child
this.notifyDataSetChanged();
expandableListView.smoothScrollToPosition(this.getChildrenCount(groupPosition));
//the 'this' is the adapter
我想修改我以前的答案b/c我发现尝试向上滚动时出现了一些问题。我创建了一个新方法
public static int getScreenHeight(){
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
Point size = new Point();
display.getSize(size);
return size.y;
}
在我的代码中,我将一个新的子项添加到列表中,我有以下内容:
adapter.notifyDataSetChanged();
listView.smoothScrollToPosition(Utility.getScreenHeight());
我只调用上面的代码,如果该项是列表的最后一项。在光标到达之前键入时会有轻微延迟,约2秒。无论如何,希望这能帮助其他人