小编Sir*_*r0n的帖子

TextInputLayout中"不允许使用元素EditText"

我正在尝试使用最新android.support.design.widget.TextInputLayout功能在Android中获取浮动标签.

通过查看文档,您似乎应该将内部元素放入EditText其中以从中受益.android:hint="myFloatingLabel"android.support.design.widget.TextInputLayout

从功能上来说,当我测试它时,它会起作用,但在Android Studio中我得到一个警告EditText:"此处不允许使用Element EditText"结果(除了我有恼人的警告之外)是它打破了所有代码完成(对于字符串资源) ,对于id资源等).

它是Android Studio的错误,还是我错过了什么?

我的代码示例信息:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingTop="@dimen/activity_vertical_margin">

    <android.support.design.widget.TextInputLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">

        <EditText
            android:id="@+id/email"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:ems="10"
            android:hint="@string/email"
            android:inputType="textEmailAddress" />
    </android.support.design.widget.TextInputLayout>

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

android

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

循环中字符串连接的误报 SonarQube 违规

我有一些看起来像这样的代码(我用通用变量替换了我的业务变量):

Map<String, String> map = new HashMap<String, String>();
for (int i = 1; i < 10; i++) {
    String suffix1 = retrieveValue1(i);
    String suffix2 = retrieveValue2(i);
    String tag = "prefix";
    if (suffix1 != null) {
      tag += suffix1;
    }
    else {
      tag += suffix2;
    }
    map.put(tag.toUpperCase(), "on");
}
Run Code Online (Sandbox Code Playgroud)

让我感到困扰的是我收到以下 SonarQube 违规:

性能 - 方法在循环中使用 + 连接字符串

在我看来,这是一个误报(因为这里的 String 没有真正的循环),但我想先仔细检查一下。

我在我的朋友 Google 上找不到任何类似的案例。

这是误报,还是我的循环中有真正的性能损失?

java sonarqube

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

标签 统计

android ×1

java ×1

sonarqube ×1