Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding two R.id in a single TextView in xml

Tags:

android

xml

I have two android:id .

For example: [ R.id.custom_font ] and [ R.id.product_name ]

In .java file

 TextView tv = (TextView)findViewById(R.id.custom_font);
    Typeface cFont = Typeface.createFromAsset(getAssets(), "fonts/jcc.ttf");
    tv.setTypeface(cFont);

// Adding items to listview
    adapter = new ArrayAdapter<String>(this, R.layout.list_item, R.id.product_name,  products);
    lv.setAdapter(adapter);

When I put them together in a single text view it shows an error message [Attribute "android:id" was already specified for element "TextView"]

In .xml file

    <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" />

How can I pass the two android:id in a single text view?

Thanks in advance.

like image 891
Asim Roy Avatar asked Jul 14 '26 15:07

Asim Roy


1 Answers

No, it is not possible. You can have only one android:id associated with one component.

like image 93
kosa Avatar answered Jul 17 '26 19:07

kosa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!