2011-08-10 6 views
1

Activity 클래스에서 파생 된 XML 파서가 있고 XML에서 Button을 파싱합니다. Android Button API를 사용하여 Button을 만들면 활동에 표시됩니다. 하지만 버튼 속성을 가져 와서 해당 클래스의 버튼을 표시하는 클래스를 만들면 표시되지 않습니다. 내가 만들고있는이 클래스는 LinearLayout을 확장하고 표시 할 수 없습니다.XML을 파싱 한 후에 버튼이 표시되지 않습니다.

GuiButton 클래스의 생성자를 필수 매개 변수와 함께 호출합니다. 아래 코드를 찾으십시오.

public class GuiButton extends LinearLayout{ 

String label; 
int type; 
public String reqType; 
public String context; 
/** 
* Network message for this button 
*/ 
public String netMsg;  
/** 
* network image id for this button 
*/ 
public String networkImageID; 
public String id; 

Button btn; 


public GuiButton(Context cntxt,String label,int type,String requestType,String netImgID, String id,String context,int priority,int commandType) { 
    super(cntxt); 



    this.setOrientation(VERTICAL);   
    btn = new Button(cntxt); 
    btn.setText(label); 
    addView(btn,new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));    
} 

활동에이 버튼을 표시하려면 어떻게해야합니까? 이 문제를 푸는데 도와주세요.

+0

기재하는대로에서 onCreate 방법을 설정하는 당신 된 setContentView (새 GuiButton (...))? 또는 선형 레이아웃이 하위보기입니까? 후자의 경우, 문제는 GuiButton의 LayoutParams (btn이 아님)에 있습니다. –

답변

1

생성자

public GuiButton(Context cntxt, String label) 

public GuiButton(Context cntxt,String label,int type,String requestType,String netImgID, String id,String context,int priority,int commandType) 

를 교체하고

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    LinearLayout l = (LinearLayout)findViewById(R.id.linear); 
    GuiButton gb = new GuiButton(this,"Hello"); 
    l.addView(gb); 
} 
관련 문제