2012-11-30 2 views
2

두 개의 android:id이 있습니다. 예를 들어XML의 단일 TextView에 두 개의 R.id 추가하기

: I는 하나의 텍스트가 에러 메시지를 표시 뷰에서 함께 넣어 된 .java 파일

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); 

의 [R.id.custom_font] 및 [R.id.product_name]

[속성 "로이드 : ID 텍스트 뷰 "]

.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를 단일 텍스트보기로 전달하려면 어떻게해야합니까?

미리 감사드립니다.

+2

이 왜 이렇게할까요? TextView를 단일 ID로 참조하십시오. –

+0

도와주세요. [Download This] (https://dl.dropbox.com/u/15065300/To-Use-Custom-Font.zip) –

답변

2

아니요, 불가능합니다. 하나의 구성 요소와 연관된 하나의 android:id 만 가질 수 있습니다. 나는 하나의 뷰에 대한 두 개의 ID를 가지고있는 점을 볼 수 없습니다

+0

사용자 정의 글꼴로 listview를 찾고 있습니다. 그런 다음 사용 자 정의 어댑터를 사용하는 것이 좋습니다. getView (int position, View convertView1, ViewGroup parent) 메소드에서이 작업을 수행 할 수 있습니다. ListView Adapter 예제를 사용자 정의 할 수 있습니다. – kumar

0

...

그냥 다음 줄에 다시 R.id.custom_font를 사용

adapter = new ArrayAdapter<String>(this, R.layout.list_item, R.id.custom_font, products); 
+0

내가 이렇게하면;
'adapter = new ArrayAdapter (this, R.layout.list_item, R.id.custom_font, R.id.product_name, products); lv.setAdapter (adapter); '
작동하지 않습니다. –

+0


'adapter = new ArrayAdapter (this, R.layout.list_item, R.id.custom_font, products) 중 하나에서 작동합니다. lv.setAdapter (어댑터); '
또는'adapter = new ArrayAdapter (this, R.layout.list_item, R.id.product_name, products); lv.setAdapter (adapter); ' –

+0

물론 ... adapter = new ArrayAdapter (this, R.layout.list_item, R.id.custom_font, products); lv.setAdapter (adapter);'정확히 내 대답에서 말한 이유입니다 ... – fiddler

관련 문제