2013-08-11 3 views
0

내 버튼 두 개를 작동 시키려고합니다. 첫 번째 단추는 첫 번째 웹보기 활동을 표시하고 두 번째 단추는 두 번째 웹보기 활동을 표시합니다. 필자의 의도와 함께 놀고 있었고 지금까지 필자는 두 번째 단추가 첫 번째 웹보기를 표시하기 때문에 무언가를해야한다는 결론에 도달했지만 첫 번째 단추는 아무 것도하지 않습니다. 어떤 제안? 두 번Android 버튼 기능이 작동하지 않습니다.

super.onCreate(savedInstanceState); 
setContentView(R.layout.main); 

:

import android.widget.Button; 

public class MainActivity extends Activity { 

    private Button button; 

    public void onCreate(Bundle savedInstanceState) {  final Context context = this; 

     super.onCreate(savedInstanceState);   setContentView(R.layout.main); 

     button = (Button) findViewById(R.id.buttonUrl); 


     button.setOnClickListener(new OnClickListener() { 

      @Override   public void onClick(View arg0) { 

       Intent intent = new Intent(context, WebViewActivity.class); 
       startActivity(intent); 

      } 

     }); 







     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
       button = (Button) findViewById(R.id.buttonurl2); 

       button.setOnClickListener(new OnClickListener() { 

        @Override 
        public void onClick(View arg0) { 

         Intent intent = new Intent(context, WebViewActivity2.class); 
         startActivity(intent); 







        }}); 



    } } 
+0

당신이 다른 버튼을 변수에 할당 시도가해야한다? – bas

+1

'super.onCreate (savedInstanceState);와'setContentView (R.layout.main);의 두 번째 호출을 제거합니다. – dst

+0

고맙습니다 !! 할 수 없었습니다. –

답변

1

왜 줄을해야합니까? 당신은 콘텐츠보기를 재설정하고, 따라서 당신은 한마디로

setContentView(R.layout.main); 

의 두 번째 호출하기 전에 만든 클릭에 변화를 잃게의를 해결하기 위해 위의 두 줄의 두 번째 모양을 제거하기 때문에 그것은 아주 잘, 문제가 될 수 문제.

+0

이제 @dst가 맞았을 수도 있습니다. 날 펀치;) – Jlewis071

0

Jlewis071의 위의 요점 이외에 두 개의 버튼에 두 개의 참조 변수를 사용하는 것이 좋습니다.

보류 버튼에 대한 참조가 하나뿐이기 때문에 마지막으로 참조 된 참조 만 보류되며 이전 참조는 삭제됩니다.

당신은

Button button1 = <your button1>; 
Button button2 = <your button2>; 
관련 문제