标签: inputconnection

Flutter:非活动 InputConnection 上的 getTextBeforeCursor

我正在尝试检索 TextField 标题中的用户输入,以便将其传递给名为 void _filterList(value). 但是,每次我输入一些文本时,都会出现以下错误:

W/IInputConnectionWrapper( 7715): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 7715): getSelectedText on inactive InputConnection
W/IInputConnectionWrapper( 7715): getTextAfterCursor on inactive InputConnection
W/IInputConnectionWrapper( 7715): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 7715): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 7715): endBatchEdit on inactive InputConnection
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

List filteredlist = [];
List entries = [];
bool isSearching = false;

getCountries() async {
  var response =
    await Dio().get('https://restcountries.eu/rest/v2/regionalbloc/eu');
return response.data;
}

@override
void initState() {
getCountries().then((data) {
  setState(() {
    entries = filteredlist = data; …
Run Code Online (Sandbox Code Playgroud)

textfield flutter inputconnection

9
推荐指数
2
解决办法
6689
查看次数

如何为自定义Android视图实现提取的文本

背景

Android中的自定义编辑器视图能够通过系统键盘接收文本InputConnection.我已经成功地做出了这样的观点.但是,当设备处于横向模式时,系统有时会选择显示提取的文本视图.当用户键入此模式时,应使用自定义视图中的相同文本更新提取的文本视图.

我无法实现提取的文本视图功能.(这是我尝试过的一些事情.)

我也无法找到任何明确的文档或完整的如何操作的例子.(这里有一些我读过的更好的东西:,,,).

MCVE

我已经创建了最基本的自定义编辑器.以下gif显示了该功能.它可以从键盘接收文本,但不会以横向方式更新提取的文本视图.因此,除非您关闭键盘,否则无法看到更新的文本.

在此输入图像描述

MyCustomView.java

public class MyCustomView extends View {

    SpannableStringBuilder mText;
    Paint mPaint;

    public MyCustomView(Context context) {
        this(context, null, 0);
    }

    public MyCustomView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public MyCustomView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        setFocusableInTouchMode(true);
        mText = new SpannableStringBuilder();
        mPaint = new Paint();
        mPaint.setColor(Color.BLACK);
        mPaint.setTextSize(60);
        mPaint.setStyle(Paint.Style.FILL);
    }

    @Override
    protected void …
Run Code Online (Sandbox Code Playgroud)

android android-custom-view inputconnection android-extracted-text

8
推荐指数
1
解决办法
272
查看次数

Android:InputConnection 缺少 getSelection() 方法

为什么我有setSelectioninInputConnection而没有getSelection()

我应该只做一个getTextBeforeCursor(VERY_HIGH_NUMBER, 0)并计算.length()那个字符串的吗?

android inputconnection

5
推荐指数
1
解决办法
914
查看次数

使用InputConnection.commitText将光标设置在插入文本的开头

对于文档InputConnection.commitText(CharSequence text, int newCursorPosition)newCursorPosition手段:

int:文本周围的新光标位置,以Java字符表示.如果> 0,则相对于文本的结尾 - 1; 如果<= 0,则相对于文本的开头.因此,值1将始终将光标前进到插入完整文本后的位置.请注意,这意味着您无法将光标定位在文本中,因为编辑器可以对您提供的文本进行修改,因此无法在此处正确指定位置.

这个例子中,如果我输入两个字符,那么将光标定位在它们之间

在此输入图像描述

然后输入另一个字符,如果我设置newCursorPosition0或无关紧要1.光标始终位于插入的末尾.例如打电话

inputConnection.commitText("aaa", 0);
Run Code Online (Sandbox Code Playgroud)

要么

inputConnection.commitText("aaa", 1);
Run Code Online (Sandbox Code Playgroud)

两者都显示如下光标:

在此输入图像描述

如果我-1

inputConnection.commitText("aaa", -1);
Run Code Online (Sandbox Code Playgroud)

我明白了

在此输入图像描述

根据文档预期1-1结果.为什么不0将光标放在插入的开头?我希望0应该是这样的

inputConnection.commitText("aaa", 0);
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

但事实并非如此.为什么不?

android android-edittext inputconnection

5
推荐指数
1
解决办法
318
查看次数

输入连接 - 如何删除所选文本?

我为Android制作了一个自定义键盘.当我按下我的键盘的退格键我使用

getCurrentInputConnection().deleteSurroundingText(1, 0);
Run Code Online (Sandbox Code Playgroud)

从输入字段中删除一个字母.但是当我选择一些文本然后按退格按钮时,不会删除所选文本.我应该使用什么方法输入连接,以便在按退格按钮时从键盘上删除所选文本?

android ime android-input-method custom-keyword inputconnection

4
推荐指数
2
解决办法
2167
查看次数

D/InputConnectionAdaptor(3218):输入法打开光标监控

这是我在文件的卡片小部件中使用的表单的一部分auth_screen.dart

child: Obx(() => Form(
      key: _formKey,
      child: SingleChildScrollView(
        child: Column(
          children: <Widget>[
            TextFormField(
              decoration: const InputDecoration(labelText: 'E-Mail'),
              keyboardType: TextInputType.emailAddress,
              validator: (value) {
                if (value!.isEmpty || !value.contains('@')) {
                  return 'Invalid email!';
                }
              },
              onSaved: (value) {
                _authData['email'] = value as String;
              },
            ),
            TextFormField(
              decoration: const InputDecoration(labelText: 'Password'),
              obscureText: true,
              controller: _passwordController,
              validator: (value) {
                if (value!.isEmpty || value.length < 5) {
                  return 'Password is too short!';
                }
              },
              onSaved: (value) {
                _authData['password'] = value as String;
              }, …
Run Code Online (Sandbox Code Playgroud)

android-emulator android-softkeyboard flutter inputconnection

2
推荐指数
1
解决办法
8238
查看次数