我一直在全國各地尋找這一點,但不知道會發生什麼......組件複製的onResume
我回來的時候到以前的活動我的組件被正確初始化,但他們對這些問題的頂新...
我的意思是,在調試模式下,我遵循和我做的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));
但事情是,第一次它的工作原理,第二個我得到上面這首彼此未初始化對象(它是另一個,因爲對象編號在調試時是相同的,如果我將按鈕背景放在按鈕上,我們可以看到前一個)
不能發佈,因爲口碑的圖像,但請看看這裏:
https://dl.dropbox.com/u/1668197/header.png
發佈您的代碼請 – 2013-03-22 20:33:53
這是不可能知道的,沒有看到你的相關代碼...點擊[編輯],以提高你的問題。 – Sam 2013-03-22 20:40:10
好的,我發佈了代碼和問題的圖片! – Nhano 2013-03-22 20:55:00