我使用名为DragListView
here的外部库。此DragListView
扩展了FrameLayout
,其中包含RecyclerView
。结构如下:
DragListView extends FrameLayout {
RecyclerView mRecyclerView;
}
填充到RecyclerView中的项目包含EditText
。屏幕顶部附近的EditText
(如果软键盘出现,则不会被覆盖)工作正常。但是,软键盘覆盖的那个将获得焦点,然后在调用myEditText.requestFocus();
时立即失去焦点,然后键盘覆盖EditText
。
以下是我的活动布局。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.example.ui.activities.ChecklistsActivity">
<include layout="@layout/custom_action_bar"
android:id="@+id/action_bar"/>
<com.woxthebox.draglistview.DragListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top"
android:id="@+id/recycler_view_checklists"
/>
</LinearLayout>
android:layout_gravity="top"
使用我的旧结构为我工作一次,其中DragListView是RecyclerView
内的嵌套子项(我设置了RecyclerView
的顶部引力),但它是&#39;在这种情况下不再工作了。
我无法使用AdjustPan
,因为它会将我的操作栏推开(但遗憾的是它有效)。我的应用程序不是全屏(仍然可以看到状态栏,我认为它不是全屏,如果我错了,请纠正我)。我尝试了一些但没什么用。
我在myEditText.setFocusable(true);
之前致电myEditText.setFocusableInTouchMode(true);
和myEditText.requestFocus();
。
我为android:descendantFocusability="afterDescendants"
或根DragListView
添加LinearLayout
。
我尝试了不同的方法来调用键盘弹出
InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
或使用已接收getCurrentFocus();
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
还有一件事以防万一。我不知道是否有与我的&#34; custom&#34;相关的任何内容。带有edtSubItemName.setImeActionLabel("Done", KeyEvent.KEYCODE_ENTER);
的键盘,因为我想要一条多线EditText
,其中包含&#34;完成&#34;动作键。 EditText
项的xml在这里:
<EditText
android:id="@+id/edit_text_sub_checklist_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/height_checklist_setting"
android:layout_marginRight="@dimen/height_checklist_setting"
android:inputType="text"
android:imeOptions="actionDone"
android:maxLength="256"
android:textSize="@dimen/text_size_default"
android:visibility="invisible" />
android:visibility="invisible"
是因为有一个按钮可以使其显示。
我生气了几天。我错过了什么吗?请随时询问更多信息。
谢谢大家宝贵的时间。
答案 0 :(得分:0)
我在设置myDragListView.setLayoutManager(layoutManager);
myDragListView.scrollToPosition(0);
解决了这个问题
然后列表从最后一项开始,所以我只需在setAdapter
之后调用 while(line !=null){
//do the macthing of data here
lines = line.split(";");
if(lines[idLoc].equalsIgnoreCase(ID)){
bool = true;
break;
}else{
bool = false;
break;
}
}
就可以像往常一样回到顶部。有趣的是,物品的位置仍然相同(仍然是从上到下)所以没有什么可做的。
希望这有助于某人。