ListView 中的 Android EditText - 键盘

Android EditText in ListView - keyboard(ListView 中的 Android EditText - 键盘)

本文介绍了ListView 中的 Android 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;
    }
  }
}

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 字段已添加到列表中.

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..
                                      -------------------------

如果我现在单击 EditText 字段,它会显示虚拟键盘并失去 EditText 的焦点.我再次单击它并获得焦点.但是如果我写东西,文本只会显示在 EditText 字段中,如果我在写的时候不经常点击它...

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?

推荐答案

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

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

这些更改可能会有所帮助.

This changes may help.

更改为列表视图:

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

更改为 mainfest.xml 中的活动:

Change to activity in mainfest.xml:

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

这篇关于ListView 中的 Android EditText - 键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:ListView 中的 Android EditText - 键盘

基础教程推荐