私は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に適切に表示されるようにするために必要な手順は何ですか?