剛剛我對android非常陌生,我有兩個android:id。結合兩個簡單的android:id或(R.id)
例如:[R.id.custom_font]和[R.id.product_name]
在java文件
TextView tv = (TextView)findViewById(R.id.custom_font);
Typeface cFont = Typeface.createFromAsset(getAssets(), "fonts/jcc.ttf");
tv.setTypeface(cFont);
adapter = new ArrayAdapter<String>(this, R.layout.list_item, R.id.product_name, R.id.custom_font, products);
lv.setAdapter(adapter);
當我在單個文本把它們放在一起查看它示出了一個錯誤消息:
[屬性 「機器人ID」 已經被用於元件 「的TextView」 指定在.xml文件
<TextView
android:textColor="?android:textColorPrimary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/custom_font"
android:id="@+id/product_name" //Attribute "android:id" was already specified for element "TextView"
android:textSize="15sp" />
如何在單個文本視圖中傳遞兩個android:id?
或其他人,如果好心幫我Download This
在此先感謝。
爲什麼不用'TextView tv =(TextView)findViewById(R.id.custom_font);'和'adapter = new ArrayAdapter''使用相同的id? –
**「我怎樣才能在單個文本視圖中傳遞兩個android:id?」** - 你不能......就這麼簡單。艾哈邁德所說的是真實的 - 對於任何UI元素(小部件)你只能有一個資源ID。這正是你遇到錯誤的原因。 – Squonk
@Squonk我發現在android中使用自定義字體[這裏](http://www.barebonescoder.com/2010/05/android-development-using-custom-fonts/)。假設這裏有一個'android:id' ** android:id =「@ + id/CustomFontText」**但是在我的項目中我已經有了一個** android:id =「@ + id/product_name」產品名稱列表中。 **那麼我怎麼能一起實現呢?**如果我使用'兩個id'或'相同的id'。模擬器顯示錯誤消息**「應用程序意外停止,請稍後再試!」**我真的很無奈! –