- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有一个 ListView,每个项目中都有一些 EditText。我对硬件键盘没有任何问题,但使用软键盘时有些问题。我有两个问题。
有关#1 的更多详细信息:
OnFocusChangeListener
会告诉我它获得焦点然后失去焦点。在视觉上,我看到光标出现在字段中,但是当键盘加载时,光标跳开(如屏幕截图所示),我不知道焦点去了哪里。 我尝试了一些 ListView 的 Focusable 和 DescendantFocusability 属性,但无济于事。有什么建议吗?
每次有焦点的 EditText 滚出 View 时,就会出现另一个醉酒光标:
更新:相关代码。
使用 ListView XML 的 Activity 布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res/com.NsouthProductions.gradetrackerpro"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.NsouthProductions.gradetrackerpro.Activity_EditCourseGPA" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="34dp"
android:text="Define the GPA and Percent scale for this course." />
<RadioGroup
android:id="@+id/radioGroup1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView1"
android:layout_marginLeft="5dp" >
<LinearLayout
android:id="@+id/linlay_rad_group_existing_scale"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RadioButton
android:id="@+id/radio0_existing_scale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:checked="true"
android:text="Existing Scale" />
<Spinner
android:id="@+id/spinner_existing_scales"
android:layout_width="wrap_content"
android:layout_height="33dp"
android:layout_gravity="right"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:id="@+id/linlay_rad_group_new_scale"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<RadioButton
android:id="@+id/radio1_new_scale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="New Scale" />
<TextView
android:id="@+id/textView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:lines="1"
android:maxLines="1"
android:text=" " />
<EditText
android:id="@+id/editText1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="textPersonName"
android:maxLines="1"
android:scrollHorizontally="true"
android:text="Gr High School Scale" >
<requestFocus />
</EditText>
</LinearLayout>
</RadioGroup>
<LinearLayout
android:id="@+id/linlay_scale_save_buttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true" >
<Button
android:id="@+id/btn_gpa_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<Button
android:id="@+id/btn_gpa_save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
<ListView
android:id="@+id/listview_scale"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/linlay_scale_save_buttons"
android:layout_alignParentLeft="true"
android:layout_below="@id/radioGroup1"
android:focusable="true"
android:focusableInTouchMode="true"
android:headerDividersEnabled="true"
android:scrollingCache="true" >
</ListView>
列表项 XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linlay_scale_list_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<CheckBox
android:id="@+id/checkbox_scale_item"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="A-" />
<EditText
android:id="@+id/et_gpa"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:enabled="true"
android:inputType="numberDecimal"
android:maxLength="6"
android:text="4.000" />
<EditText
android:id="@+id/et_min"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:enabled="true"
android:inputType="numberDecimal"
android:maxLength="6"
android:text="94.75" />
<EditText
android:id="@+id/et_max"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="numberDecimal"
android:maxLength="6"
android:text="100.0" />
在我的适配器中设置 View :
View v = convertView;
ViewHolder holder;
v = inflater.inflate(R.layout.scale_list_item,
holder = new ViewHolder();
holder.cb = (CheckBox) v.findViewById(R.id.checkbox_scale_item);
holder.et_gpa = (EditText) v.findViewById(R.id.et_gpa);
holder.et_min = (EditText) v.findViewById(R.id.et_min);
holder.et_max = (EditText) v.findViewById(R.id.et_max);
我不确定还要发布什么。我有 focus 和 textChange 监听器,但即使将它们注释掉,问题仍然存在。让我知道是否还需要其他任何东西。谢谢。
有关触摸 EditText 时焦点的行为方式的更多详细信息:
requestChildFocus
... 似乎没有成功)。 以上是基于同时拥有 EditText 和 ListView 的监听器。 注意:使用硬件键盘时,EditText 获得焦点,仅此而已。我认为出现的软键盘会影响焦点。
最终更新:最后,使用 ListView 太困难了,尤其是因为我想根据对一行中 EditText 的更改更新多行。当键盘打开并且 ListView 只考虑在任何时候存在的几行时,这很难做到。
我改为制作嵌套的 LinearLayouts。每个水平布局都是一个“行”,我将它们放在 ArrayList 中以便管理它们,相对而言(仍然不容易),这是小菜一碟。
最佳答案
您正面临 ListView
回收问题。当您向上或向下滚动或键盘出现时 ListView
再次刷新并失去您的 EditText
焦点。所以,首先阅读 this answer to understand ListView
Recycling mechanism然后按照我这边的建议在我的脑海中解决你当前的场景。
我建议您应该在ListView
项上使用Button
,此按钮的文本应该是通用的,例如Enter Student Info 或任何您喜欢的内容。单击此 Button
后打开 AlertDialog
并设置您的 xml View (当前您所有的 edittexts
如 et_gpa、et_min、et_max 等在 listview 上
项目)
例如:
btnInfo.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
showStudentInfoAlert();
}
});
public void showStudentInfoAlert()
{
AlertDialog.Builder builder = new AlertDialog.Builder(context);
LayoutInflater in = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = in.inflate(R.layout.your_xml_having_edittexts, null);
EditText et_gpa = (EditText) v.findViewById(R.id.et_gpa);
//add all edit texts like this and after that just set view on alert dialog
builder.setTitle("Enter student's info");
builder.setView(v);
builder.setPositiveButton("Save", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//save all edittexts values and do what erver you want with those values
}
});
dialog.show();
}
关于android - 在 ListView (Android) 中聚焦 EditTexts 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26519247/
我之前在论坛上发布过这个,但我想我不太清楚。我有一个侧边栏 ListView 和一个包含我的控件的主面板。我想在 oncreate() 中突出显示 listview 中的 Activity 项,因为每
这里有没有人知道我如何通过 onTap() 扩展 ListView 项(在本例中为卡片)的内容 - 以显示更多选项?您知道那里有可以提供帮助的酒吧吗? 我已经看过了,但我不知道要搜索什么?我相信你们都
我的 ListView 控件有问题。我希望我的奇数行和偶数行具有不同的颜色,但我想通过代码而不是 FXML 来实现。例如: 第一行 - 绿色 第二行 - 红色 第三行 - 绿色 第四行 - 红色 现在
我有一个 ListView 。我想让单元格背景透明。目前,我正在做以下事情: .list-cell { -fx-background-color: transparent; } 但是,细胞的颜
我想创建一个几乎无限的元素列表,但我想将列表的初始位置设置为某个特定元素。像这张图片: 其中索引 0 将是初始位置,并且此列表可能会也可能不会在两个方向上延伸很长。 我可以像这样创建我的元素: W
有没有办法在JavaFX中获取ListView的可见项?我想确定 JavaFX 应用程序中 ListView 显示的第一个可见项。 以下代码found here不适合我(仅适用于 TableView)
开发人员。 我尝试在水平方向拉伸(stretch) ListView 项目。我确实重置了 ItemContainerStyle ,并且水平对齐是拉伸(stretch)的。这是 MainPage.xam
有没有办法在JavaFX中获取ListView的可见项?我想确定 JavaFX 应用程序中 ListView 显示的第一个可见项。 以下代码found here不适合我(仅适用于 TableView)
我想问一下: 我有一个预定义顺序的数组。 var order=new Array(); order[0]="Tesco"; order[1]="Interspar"; order[2]="
我希望创建以下内容:当到达内部 Listview 的顶部或底部时,我想继续在顶部 Listview 中滚动。见动图: Gif of what I got so far 一个选项是在到达底部时将内部 L
我正在尝试在 ajax 发布后刷新 jQuery 移动 ListView ,我一直在尝试使用 .trigger("create") 来执行此操作,如下所示: Most Played
我真的不明白是什么导致了错误我检查了文档,这里有一个非常相似的例子是我的 views.py,我使用的应用程序下的 urls.py 包含,以及模板 View .py class SchoolListVi
我有这个父布局 parent_listview 的列表项具有这种布局 child_listview 的项目有这个布局
我在单击列表项时获取 listview 项 时遇到问题。我得到了 simple listview(Arrayadapter) 的 listview item,但我遇到了 custom listview
我有一个工作正常的 DropdownMenu,但我需要一个 ListView,但我无法转换它。 DropdownMenu 如下所示: // Create the List of devices t
我想实现一个可滚动(垂直)且其中包含元素的屏幕。所以我把它放在 listview.builder 上。问题是,其中一个元素是另一个水平滚动的 listview.builder。当我实现它时,horiz
帮助!我想不通! 为了帮助我学习 SwiftUI,我正在使用 ListView 制作一个简单的杂货 list 应用程序。点击列表中的每个项目时,有些按钮会变成绿色或红色。 在我向列表数组中添加太多项目
所以我知道我们可以等待 ListView 加载,然后显示它。但是,如果我们动态加载正在下载的图像,ListView 将加载但图像尚未加载,因此它们不会出现在 ListView 中。 可接受的等待 Li
我是 Android 的新手,正在努力提高编程技能。 在这里,我有自定义 ListView 适配器类,我曾在其中显示 ListView 项目,如 TextView 、图像等。 我需要做的是,我在 Li
So, what I want is to individually disable a button for the concerned item in the ListView when clic
我是一名优秀的程序员,十分优秀!