2014-02-14 2 views
0

android의 맞춤보기에 버튼을 추가하려면 어떻게해야하나요? 사용자 정의보기를 사용하고 있지만 그래픽 레이아웃을 사용하여 활동에 단추를 추가하면 작동하지 않으며 사용자 정의보기가 활동에 표시되므로 단추를 추가 할 수 있습니다.android의 맞춤보기에 버튼을 추가하려면 어떻게해야하나요?

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    myView = new CustomView(this); 
    myView.setGame(new Game()); 
    setContentView(myView); 

    Button exitGameButton = new Button(this); 
    exitGameButton .setGravity(Gravity.CENTER); 
    exitGameButton .setText("Done"); 
    myView.addView(exitGameButton); 
    } 
는 그럼 어떻게 지금은 다른 활동으로 변경해야합니까 또한, 제가 그것을 실행할 때

public void addView(Button exitGameButton) { 
    // TODO Auto-generated method stub 

} 

버튼이 표시되지 않습니다 내있는 CustomView에 메소드를 추가했다?

답변

0

, 프로그램 단지 버튼

Button myButton = new Button(this); 

을 만들어보기로

myView.addView(myButton); 

더 자세한 예를 추가 활동에

private View v; 

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
    v = inflater.inflate(R.layout.main_layout, container, false); 
    CustomView myCustomView = (CustomView) v.findViewById(R.id.customView1); 
    //Create button. 
    Button myButton = new Button(this); 
    //Add button to your custom view. 
    myCustomView.addView(myButton); 
+0

를? – user3267882

+0

또한 그래픽 레이아웃의 단추를 추가합니까? – user3267882

+0

그렇다면 표시 할 곳을 어떻게 보냅니 까? 내가하고 싶은 일은? – user3267882

관련 문제