2016-07-22 139 views
0
Note: This string resource has the same name as the element ID: edit_message. However, references to resources are always scoped by the resource type (such as id or string), so using the same name does not cause collisions. " 

在上面什麼呢給出文本「引用資源總是作用域」在上下文中是指以下XML片段添加字符串資源

<EditText android:id="@+id/edit_message" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:hint="@string/edit_message" /> 
+0

恩,給我們看你的strings.xml文件....? – Razgriz

+0

保持更改edit_message在String.xml文件中的edit_mes並嘗試在編輯文本提示中使用android:hint =「@ string/edit_mes」 –

回答

0

作用域@id/@string/

你的兩個ID都是相同的,但它們不會因爲它們在不同的範圍而相互碰撞

0

此字符串資源具有相同的名稱作爲元素ID:edit_message

在這裏,字符串資源具有名稱作爲edit_message和EDITTEXT也具有名稱edit_message

引用資源總是由資源型

作用域這意味着,如果你正在做R.id.edit_message那麼它將範圍的EDITTEXTedit_text。因爲這指的是id類型。

如果你這樣做R.string.edit_text,它將範圍的字符串edit_text類型,因爲這是指一個字符串類型。

因此有人說,引用資源總是由資源型

0

作用域這意味着,你的ID和串都具有相同的name.But都具有兩種不同的範圍。 @id將尋找R.id.edit_message即id類,而@string將尋找R.string.edit_message

所以不要擔心一切都很好。