Android ListView 中的 EditText - 键盘

发布于 2024-12-17 15:09:24 字数 2631 浏览 0 评论 0原文

我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一梦浮鱼 2024-12-24 15:09:24

如果这仍然是一个问题,请查看此项目:ListView 内的可聚焦 EditText

此更改可能有帮助。

更改为列表视图:

<ListView
    android:id="@android:id/list" 
    android:layout_height="fill_parent" 
    android:layout_width="fill_parent"
    android:descendantFocusability="beforeDescendants"
    />

更改 mainfest.xml 中的活动:

<activity android:name= ".yourActivity" android:windowSoftInputMode="adjustPan"/>

If this is still an issue, take a look at this item: Focusable EditText inside ListView

This changes may help.

Change to listview:

<ListView
    android:id="@android:id/list" 
    android:layout_height="fill_parent" 
    android:layout_width="fill_parent"
    android:descendantFocusability="beforeDescendants"
    />

Change to activity in mainfest.xml:

<activity android:name= ".yourActivity" android:windowSoftInputMode="adjustPan"/>
南街女流氓 2024-12-24 15:09:24

有时,当您在清单 Activity 或 xml 中使用 android:windowSoftInputMode="stateAlwaysHidden" 时,它会失去键盘焦点。因此,首先检查 xml 和清单中是否有该属性,如果存在,请将其删除。将这些选项添加到侧活动中的清单文件 android:windowSoftInputMode="adjustPan" 并将此属性添加到 xml 中的 listview android: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 activity android:windowSoftInputMode="adjustPan"and add this property to listview in xml android:descendantFocusability="beforeDescendants"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文