You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

TableRow中的EditText无法获取焦点/输入内容问题求助

Fixing EditText Input Issue in TableLayout's TableRow

Hey there, let's work through this problem where your EditText inside a TableRow won't accept input! Since the ListView workarounds didn't help, here are some specific fixes tailored to TableLayout scenarios:

  • Disable focus on TableRow
    TableRow might be stealing focus from the EditText, preventing it from receiving user input. Add these attributes to your TableRow in XML:

    <TableRow
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:focusable="false"
        android:focusableInTouchMode="false">
    
        <EditText
            android:id="@+id/input_edittext"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:hint="Type something here"/>
    </TableRow>
    
  • Verify EditText's editable state
    Double-check that your EditText isn't accidentally set to non-editable. Remove any android:editable="false" (deprecated in API 15) and ensure you've set a valid input type like android:inputType="text". Also confirm you haven't called setEnabled(false) or setFocusable(false) on the EditText in your code.

  • Prevent touch event interception
    Sometimes TableLayout/TableRow intercepts touch events before they reach the EditText. Create a custom TableRow class to bypass this:

    public class FocusableTableRow extends TableRow {
        public FocusableTableRow(Context context) {
            super(context);
        }
    
        public FocusableTableRow(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
    
        @Override
        public boolean onInterceptTouchEvent(MotionEvent ev) {
            // Let EditText receive touch events directly
            View targetView = findChildViewUnder(ev.getX(), ev.getY());
            if (targetView instanceof EditText) {
                return false;
            }
            return super.onInterceptTouchEvent(ev);
        }
    }
    

    Then use this custom row in your XML instead of the default TableRow.

  • Force focus and show keyboard
    If the issue is that the EditText isn't getting focus or the keyboard isn't popping up, trigger it explicitly in your code:

    EditText inputEditText = findViewById(R.id.input_edittext);
    inputEditText.requestFocus();
    
    // Show soft keyboard
    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.showSoftInput(inputEditText, InputMethodManager.SHOW_IMPLICIT);
    

Give these steps a try—one of them should get your EditText accepting input again!

内容的提问来源于stack exchange,提问作者Connor Brady

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 08:34:44