私はこれをずっと探していましたが、何が起こるかわかりません...
前のアクティビティに戻ると、コンポーネントは正しく初期化されていますが、その上に新しいコンポーネントがあります...
つまり、デバッグモードでは、onResumeコードに従い、テキストが書き込まれ、onCLicklistenersが設定されますが、適切なコンポーネントの上に空のコンポーネントが表示され、理由がわかりません。
もちろん、アプリが最初に作成されたときは正常に動作します!
何か案が?
関連するコード:コンポーネント
public class TopLayout extends RelativeLayout {
public static final int BTN_LEFT = 0;
public static final int BTN_RIGHT = 1;
public static final int LBL_TITLE = 2;
protected Button btnLeft;
protected Button btnRight;
protected TextView lblTitle;
public TopLayout(Context _context, AttributeSet _attrs) {
super(_context, _attrs);
}
public TopLayout(Context _context) {
super(_context);
}
public TopLayout(Context _context, AttributeSet _attrs, int _defStyle) {
super(_context, _attrs, _defStyle);
}
public void initialize(){
String infService = Context.LAYOUT_INFLATER_SERVICE;
LayoutInflater li = (LayoutInflater) getContext().getSystemService(infService);
li.inflate(R.layout.top_layout, this, true);
btnLeft = (Button)findViewById(R.id.btnLeft);
btnRight = (Button)findViewById(R.id.btnRight);
lblTitle = (TextView)findViewById(R.id.lblTitle);
}
public void setText(int _element, String _text){
switch (_element) {
case BTN_LEFT:
btnLeft.setText(_text);
break;
case BTN_RIGHT:
btnRight.setText(_text);
break;
case LBL_TITLE:
lblTitle.setText(_text);
break;
default:
throw new RuntimeException("Unknown element to set Text: " + _text);
}
}
public void hideButton(int _element){
switch (_element) {
case BTN_LEFT:
btnLeft.setVisibility(Button.GONE);
break;
case BTN_RIGHT:
btnRight.setVisibility(Button.GONE);
break;
default:
throw new RuntimeException("Unknown button to hide: " + _element);
}
}
public void setClickAction(int _element, OnClickListener _listener){
switch (_element) {
case BTN_LEFT:
btnLeft.setOnClickListener(_listener);
break;
case BTN_RIGHT:
btnRight.setOnClickListener(_listener);
break;
case LBL_TITLE:
lblTitle.setOnClickListener(_listener);
break;
default:
throw new RuntimeException("Unknown button to activate: " + _element);
}
}
}
私の活動のonResume:
topLyt = (TopLayout) findViewById(R.id.lytTop);
topLyt.initialize();
topLyt.setText(TopLayout.BTN_LEFT, res.getString(R.string.edit));
topLyt.setText(TopLayout.LBL_TITLE, res.getString(R.string.involved_people));
topLyt.setText(TopLayout.BTN_RIGHT, res.getString(R.string.add));
しかし、最初に機能するときは、2番目にこの最初のオブジェクトの上に初期化されていないオブジェクトがあります(デバッグ中にオブジェクト番号が同じであるため、別のオブジェクトになる必要があります。前のオブジェクトを配置すると、前のオブジェクトを確認できます。ボタンのシースルー背景)
評判のため画像を投稿できませんが、こちらをご覧ください: