【问题标题】:EditTexts inside ExpandableListViewExpandableListView 内的 EditTexts
【发布时间】:2011-10-15 06:43:41
【问题描述】:

您好,我正在尝试制作一个显示 ExpandableListView 的活动,如图所示。

当您单击该组时,它会展开并显示一个带有 textview 和 editext 的 LinearLayout。

知道我遇到的问题是,当单击 EditText 时它没有获得焦点,我必须在它上面点击两次才能使其获得焦点并显示键盘,然后当我输入文本时我在我输入时最初什么也看不到,然后当我隐藏键盘时,EditText 会使用我输入的文本进行更新

我尝试将 android:descendantFocusability="afterDescendants" 添加到 expandableListVie 布局,但行为相同。

有什么想法吗??或任何其他方式我可以实现这个布局??

【问题讨论】:

  • 嘿,你能帮帮我吗。你能告诉我当这个组项目被折叠时如何获得编辑文本值。我想在底部按钮事件上使用这个编辑文本值
  • jucas,你找到解决这个问题的方法了吗?

标签: android layout android-edittext expandablelistview


【解决方案1】:

在您的活动中的 android:name 之后将其添加到清单中

 android:windowSoftInputMode="adjustPan"

【讨论】:

    【解决方案2】:

    我不知道如何解决聚焦问题,但我知道为什么必须折叠和展开组才能看到 editText 中的文本。除非您滚动或执行诸如展开和折叠列表视图之类的操作,否则列表视图不会刷新。因此,我能想到的解决此问题的最佳方法是创建一个字符串列表,该列表将作为列表视图中 editTexts 的值。然后为每个 editTexts 创建一个 onKeyClick() 侦听器并执行以下操作:

    editText1.setOnKeyListener(new EditText.OnKeyListener()
    {
        public boolean onKey(View editText, int keyCode, KeyEvent keyEvent)
        {
            // Get the position of the item somehow
            int position = 4;
            // Get value from List<String> for editTexts
            String textValue = listOfValues.get(position);
            textValue = ((EditText)editText).getValue();
            adapter.notifyDataSetChanged();
            return false;
        }
    });
    

    这里发生的情况是,一旦按下某个键,您将获取 editText 的值,并将列表中字符串的值更改为新值。然后您告诉适配器其中一项的值已更改,需要刷新。虽然这不是解决问题的有效方法,但它是一种备用解决方案,以防您想不出更好的方法。

    【讨论】:

    • 但是等一下你会用 listOfValues 做什么
    • 您不必对 listOfValues 做任何事情,因为字符串 'textValue' 已绑定到 listOfValues 中的字符串。因此,当 textValue 的值发生变化时,listOfValues 中的值也会发生变化。
    【解决方案3】:

    尝试使用函数将Edittext中的值存储到String变量中

    String temp;
    
    editText.addTextChangedListener(new TextWatcher() {
    
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // TODO Auto-generated method stub
    
        }
        public void beforeTextChanged(CharSequence s, int start, int count,
        int after) {
            // TODO Auto-generated method stub
    
        }
    
        public void afterTextChanged(Editable s) {
            // TODO Auto-generated method stub
    
            temp = s.toString();//editText.getText().toString();
    
            childValues[groupPosition][childPosition][]= temp ;
    
            Toast.makeText(context, ""+childValues[groupPosition][childPosition], Toast.LENGTH_SHORT).show();
        }
    });
    

    并且在 getChild() 函数中始终检查 temp 中的数据和 settext() 值到特定的 edittext

    【讨论】:

      【解决方案4】:

      你必须添加两件事。

      1) expandableListView.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);

      2)在清单中(关于你的活动)android:windowSoftInputMode="adjustPan"

      【讨论】:

        猜你喜欢
        • 2011-11-16
        • 2019-01-26
        • 2016-08-17
        • 2013-05-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多