【问题标题】:cannot type in edittext inside the expandable listview无法在可展开的列表视图中输入edittext
【发布时间】:2012-12-30 11:47:08
【问题描述】:

我正在使用包含 2 个不同子项的可扩展 ListView。子布局包含 3 个 EditText 字段。当我展开组时,它会显示子布局,但我无法在 edittext 字段中键入任何文本。

我在自定义可扩展列表适配器中的代码如下:

public View getChildView(int groupPosition, int childPosition, boolean arg2, View childView,
        ViewGroup parent) 
{
    switch (groupPosition)
    {
    case 0:
        childView = inflater.inflate(R.layout.edit_personal_layout, null);
        final EditText fname = (EditText)childView.findViewById(R.id.editTextFname);
        fname.setOnClickListener(new OnClickListener() {

            public void onClick(View arg0) 
            {
                // TODO Auto-generated method stub
                fname.setFocusable(true);
            }
        });

        break;
    case 1:
        childView = inflater.inflate(R.layout.edit_experience_layout, null);
        break;
    case 2:
        childView = inflater.inflate(R.layout.edit_qualification_layout, null);
        break;
    case 3:
        childView = inflater.inflate(R.layout.edit_login_layout, null);
        break;
    case 4:
        childView = inflater.inflate(R.layout.edit_other_layout, null);
        break;
    }

    return childView;
}


public View getGroupView(int position, boolean arg1, View view, ViewGroup parent) 
{
    if(view==null)
    {
        view = inflater.inflate(R.layout.edit_head, null);

    }
    TextView head = (TextView)view.findViewById(R.id.list_item_text_view_head);
    head.setText(menu[position]);
    return view;
}

【问题讨论】:

    标签: android expandablelistview android-edittext


    【解决方案1】:

    1) 可能是您的editText 没有获得焦点,这就是您无法输入任何内容的原因。尝试将下面的行放入xml-layout 文件中。

     android:descendantFocusability="blocksDescendants"
    

    有关赋予子元素焦点的更多信息,您可以参考此link

    2) 如果上述解决方案不起作用,您可以尝试在 listview 中添加。

    <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"/>
    

    3) 如果仍然无法正常工作,请查看 link (focusable-edittext-inside-listview)link

    希望这能解决您的问题。

    【讨论】:

    • 我想在哪里添加这一行。使用 expandableListView 还是使用子布局??
    • 但是当我使用“blocksDescendants”时,我无法获得焦点。但是我使用“afterDescendants”而不是“blocksDescendants”,但是当我移动到下一个文本框时,我丢失了我输入的内容ist 文本框
    • 将上述行加入到XML文件(editText所在的XML文件)最外层的布局结构中。
    • 但是当我使用“blocksDescendants”时我没有得到焦点
    • 这里我只是在可扩展列表视图中使用 android:descendantFocusability="afterDescendants" 现在我可以输入 int 文本框但不能将文档移动到下一个焦点
    【解决方案2】:

    Here is a similar answer “adjustPan”是存储客户输入的关键。另一种聚焦方式:

    <TextView
         android:id="@+id/e_text_label"...>
        <requestFocus /> </TextView>
    

    【讨论】:

      猜你喜欢
      • 2017-10-03
      • 1970-01-01
      • 1970-01-01
      • 2011-10-14
      • 1970-01-01
      • 1970-01-01
      • 2013-11-08
      • 1970-01-01
      • 2016-02-06
      相关资源
      最近更新 更多