2017-12-12 2 views
-1

나는 텍스트 뷰의 값 변경할 수 있습니다맞춤 속성의 값을 변경하는 방법은 무엇입니까?

textTem = (TextView) findViewById(R.id.textTem); 
    textTem.setText("ssss"); 

을하지만 사용자 정의 속성을 가진 사용자 지정 구성 요소를 가지고 : "안드로이드 : 텍스트를"쉽게 때문이다.

내 사용자 지정 구성 요소 클래스 : XML의

 public class DayItem extends RelativeLayout { 
      ... 
     } 

내 사용자 지정 구성 요소 :

 <com.example.a28210.weathpredict.DayItem 
      android:id="@+id/days1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      item:dayweather="snow" 
      item:daymaxtem="-2°" 
      item:daymintem="-12°" 
      item:daydate="12.8" /> 

내 사용자 정의 속성 :

  <?xml version="1.0" encoding="utf-8"?> 
      <resources> 
       <declare-styleable name="DayItem"> 
        <attr name="daydate" format="string" /> 
        <attr name="dayweather" format="string" /> 
        <attr name="daymaxtem" format="string" /> 
        <attr name="daymintem" format="string" /> 
       </declare-styleable> 
      </resources> 

내 질문은 : 변경할 수있는 방법이 없습니다 커스텀 속성의 값
acustom 속성의 값을 변경하려면 어떻게해야합니까?

    DayItem d=(DayItem)view.findViewById(R.id.days1); 
        d.  //????? 
+3

"acustom 속성의 값을 변경할 방법이 없습니다."- 추가하십시오. 당신은'com.example.a28210.weathpredict.DayItem'을 썼습니다. 거기에 메소드를 추가 할 수 있습니다. – CommonsWare

+0

'setText' 메소드는 XML 정의에서 자동으로 생성되지 않습니다. –

답변

0

보기의 변경 값은 사용자 지정 특성의 값을 변경하지 않고 사용자 지정 특성을 사용합니다.

사용자 지정 특성을 사용하여 XML에서 값을 전달하여 사용자 지정보기에서 사용합니다. 다음 수

DayItem d = (DayItem)view.findViewById(R.id.days1); 
d.setWeather("Sunny") 

희망이

public class DayItem extends RelativeLayout {     
     ... 
     void setWeather(String value){ 
     someView.text = value 
     } 
     ... 

    } 

:

someView.text = getString(R.styleable.DayItem_dayweather) //return "snow" 

지금 당신은 당신의 사용자 정의보기에 메소드를 추가, 런타임에서 someView의 값을 변경하려면 : 예를 들어 도와 줘.