小编Mal*_*olm的帖子

使用TextWatcher进行EditText验证

我有一个带有a EditText和按钮的Dialog .这EditText将命名我将创建的数据库表,以便验证它的最重要性.所以我想提出2个问题:

1)这很简单,但我无法在任何地方找到它:数据库表名称可以接受哪些字符?可以接受号码吗?并且数字可以是第一个字符吗?

2)我设法验证EditText使用TextWtacher.这是代码:

et_name.addTextChangedListener(new TextWatcher() {

public void afterTextChanged(Editable s) {

    String filtered_str = s.toString();

        if (filtered_str.matches(".*[^a-z^0-9].*")) {

        filtered_str = filtered_str.replaceAll("[^a-z^0-9]", "");

        s.clear();

        // s.insert(0, filtered_str);

        Toast.makeText(context,
            "Only lowercase letters and numbers are allowed!",
            Toast.LENGTH_SHORT).show();

    }

}

    public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

    public void onTextChanged(CharSequence s, int start, int before, int count) {}
});
Run Code Online (Sandbox Code Playgroud)

目前,如果用户插入除小写字母和数字以外的任何字符,则清除文本框.如果我取消注释s.insert(0, filtered_str);以使用过滤后的字符串替换EditText,我的应用程序将挂起.猜猜我在调试中发现了什么?

错误/ AndroidRuntime(2454):java.lang.StackOverflowError = D.

问题是......我怎样才能替换s文本?

- …

java string android textwatcher android-edittext

7
推荐指数
2
解决办法
2万
查看次数

如何使用API​​创建电报贴纸包?

我想在软件中添加贴纸包给Telegram.我不知道该怎么做.如何使用API​​执行此操作?

android telegram

7
推荐指数
1
解决办法
1625
查看次数

如何将操作栏中的项目对齐到左侧?

我有一个带有searchview的操作栏,但是我想将它对齐到左边,例如在地图应用程序中,而不是右边.我该怎么做?

android android-3.0-honeycomb android-actionbar

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

如何使用记笔记语音操作创建Android Wear应用程序?

我似乎无法弄清楚如何创建一个Android Wear应用程序,它允许我通过内置语音操作使用它来记笔记.我声明了添加语音功能中所述的intent过滤器:

<intent-filter>
    <action android:name="android.intent.action.SEND"/>
    <category android:name="com.google.android.voicesearch.SELF_NOTE"/>
</intent-filter>
Run Code Online (Sandbox Code Playgroud)

但是,这没有任何作用,手机上的Wear应用程序不允许我将应用程序设置为默认的笔记记录应用程序.我需要做些什么来实现这一目标?

android wear-os

3
推荐指数
1
解决办法
958
查看次数

如何根据当前屏幕方向设置活动内容?

我只是想做:

if(getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)
    setContentView(R.layout.search_portrait);
else
    setContentView(R.layout.search_landscape);

问题是 - getRequestedOrientation总是返回-1.

有什么建议?

android

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