2016-05-29 12 views
0

私は2つのテキストビューと別々のカスタムアダプタクラスからなるカスタムビュークラスを持っています。 カスタムビュークラスでは、私が実装と2 textviewsのテキストを設定する方法があります:setText()メソッドはカスタムビューで正しいテキストを表示しません[ANDROID]

public class CompoundView extends LinearLayout { 

private TextView versionNameView; 
private TextView versionNumberView; 
private Context mContext; 

public CompoundView(Context context, AttributeSet attrs) { 
    super(context, attrs); 
    mContext=context; 
    TypedArray a = context.obtainStyledAttributes(attrs,R.styleable.ColorOptionsView, 0, 0); 
    String titleText = a.getString(R.styleable.ColorOptionsView_titleText); 

    int valueColor = a.getColor(R.styleable.ColorOptionsView_valueColor,getResources().getColor(android.R.color.holo_blue_light)); 
    a.recycle(); 

    setOrientation(LinearLayout.VERTICAL); 
    setGravity(Gravity.CENTER_VERTICAL); 

    LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    View rootView = inflater.inflate(R.layout.view_color_options, this, true); 
    versionNameView = (TextView) this.findViewById(R.id.list_item_title); 
    versionNumberView = (TextView) this.findViewById(R.id.list_item_content); 

} 

public CompoundView(Context context) { 
    this(context, null); 


} 

public void setTexts(String text1,String text2) { 
    versionNameView.setText(text1); 
    versionNumberView.setText(text2); 
} 
} 

を、私のカスタムアダプタで、オーバーライドされたgetViewメソッド()メソッドのセクションの内側に、私は実装:

... 
CompoundView customView = new CompoundView(yContext); 
customView.setTexts("Test1","Test2"); 
... 

私は、アプリケーションを実行すると、UIのテキストが元の値(元々はプログラムで宣言されているものではなくXMLで宣言されている)を表示しています。 しかし、カスタムビュー内でversionNameView.getText()versionNumberView.getText()を実行しようとすると、logcatは正しく更新された値を表示しています。 更新されたテキストがUIに適切に表示されるようにするために必要な手順は何ですか?

答えて

0

正常に動作するように管理しました。 ビューのオブジェクトを作成する代わりに、findViewById()オペレーションを使用して、XMLファイルの既存の作成されたカスタムビューを参照する必要があります。

関連する問題