Android ListView 中的 EditText - 键盘
我的 EditText
有问题。我使用以下适配器:
public class RowTextViewAdapter extends BaseAdapter {
...
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
if (rowTitles.get(position).equals("edit")) {
if(et == null){
et = new EditText(activity);
et.setText("Test");
}
return et;
}
else {
convertView = new TextRow(activity);
holder = new ViewHolder(((TextRow) convertView).getTextView(), ((TextRow) convertView).getImageView());
convertView.setTag(holder);
holder.getTextView().setText(StringManager.getInstance().getText(rowTitles.get(position), activity));
holder.getImageView().setImageBitmap(assetController.getBitmap(additiveIcons.get(position) + ".png", null));
return convertView;
}
}
}
和 ListActivity
:
public class AppSettingActivity extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
adapter = new RowTextViewAdapter(this);
adapter.addRowView("account", "arrowDw");
adapter.addRowView("password", "arrowDw");
setListAdapter(adapter);
}
...
protected void onListItemClick(ListView listView, View view, int position, long id) {
switch (position) {
case 0: accIsEditable = adapter.setEditable(position); break;
case 1:
if(accIsEditable) {
//TODO do something..
break;
}
pwIsEditable = adapter.setEditable(position);
break;
...
}
}
如果我单击第一个项目,我会在 pos 上添加一个新的列表项目。 1(位置:0、1、2、...)。 现在,EditText
字段已添加到列表中。
ListView:
---------------------------- -------------------------
Account v Account ^
---------------------------- ==> -------------------------
Passowrd v [::::::::EditText:::::::]
---------------------------- -------------------------
//more.. Password v
---------------------------- -------------------------
//more..
-------------------------
如果我现在单击 EditText
字段,它会显示虚拟键盘并失去 EditText
的焦点。我再次单击,它获得焦点。但是,如果我写一些东西,文本只会显示在 EditText
字段中,如果我在写作时点击它而不是频繁地点击它......
有解决更新问题的想法吗?
I've got a problem with my EditText
. I use the following adapter:
public class RowTextViewAdapter extends BaseAdapter {
...
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
if (rowTitles.get(position).equals("edit")) {
if(et == null){
et = new EditText(activity);
et.setText("Test");
}
return et;
}
else {
convertView = new TextRow(activity);
holder = new ViewHolder(((TextRow) convertView).getTextView(), ((TextRow) convertView).getImageView());
convertView.setTag(holder);
holder.getTextView().setText(StringManager.getInstance().getText(rowTitles.get(position), activity));
holder.getImageView().setImageBitmap(assetController.getBitmap(additiveIcons.get(position) + ".png", null));
return convertView;
}
}
}
and ListActivity
:
public class AppSettingActivity extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
adapter = new RowTextViewAdapter(this);
adapter.addRowView("account", "arrowDw");
adapter.addRowView("password", "arrowDw");
setListAdapter(adapter);
}
...
protected void onListItemClick(ListView listView, View view, int position, long id) {
switch (position) {
case 0: accIsEditable = adapter.setEditable(position); break;
case 1:
if(accIsEditable) {
//TODO do something..
break;
}
pwIsEditable = adapter.setEditable(position);
break;
...
}
}
If i click on the first item I add a new list item on pos. 1 (pos: 0, 1, 2, ...).
Now the EditText
field is added to the list.
ListView:
---------------------------- -------------------------
Account v Account ^
---------------------------- ==> -------------------------
Passowrd v [::::::::EditText:::::::]
---------------------------- -------------------------
//more.. Password v
---------------------------- -------------------------
//more..
-------------------------
If I click now into the EditText
field, it shows the virtual keyboard and loses focus of the EditText
. I click again and it gains focus. But if I write something, the text is only showed in the EditText
field, if i tap on it and not frequently while i'm writing...
Any idea to fix that update problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果这仍然是一个问题,请查看此项目:ListView 内的可聚焦 EditText
此更改可能有帮助。
更改为列表视图:
更改 mainfest.xml 中的活动:
If this is still an issue, take a look at this item: Focusable EditText inside ListView
This changes may help.
Change to listview:
Change to activity in mainfest.xml:
有时,当您在清单 Activity 或 xml 中使用
android:windowSoftInputMode="stateAlwaysHidden"
时,它会失去键盘焦点。因此,首先检查 xml 和清单中是否有该属性,如果存在,请将其删除。将这些选项添加到侧活动中的清单文件android:windowSoftInputMode="adjustPan"
并将此属性添加到 xml 中的 listviewandroid:descendantFocusability="beforeDescendants"
some times when you use
android:windowSoftInputMode="stateAlwaysHidden"
in manifest activity or xml, that time it will lose keyboard focus. So first check for that property in your xml and manifest,if it is there just remove it. After add these option to manifest file in side activityandroid:windowSoftInputMode="adjustPan"
and add this property to listview in xmlandroid:descendantFocusability="beforeDescendants"