2012-07-12 4 views
-1

지난 몇 주 동안 이것을 설정하려고했지만 성공하지 못했습니다. 어떻게이 두 블록의 코드를 같은 Java 클래스에 넣을 수 있습니까?admob 및 활동

private int entries = 6; 
private String phoneNum[]; 
private String buttonLabels[]; 

/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 

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

    phoneNum = new String[entries]; 
    buttonLabels = new String[entries]; 

    // Populate the data arrays 
    populateArrays(); 

    // Set up buttons and attach click listeners 

    Button button1 = (Button)findViewById(R.id.button1); 
    button1.setText(buttonLabels[0]); 
    button1.setOnClickListener(this); 

    Button button2 = (Button)findViewById(R.id.button2); 
    button2.setText(buttonLabels[1]); 
    button2.setOnClickListener(this); 

    Button button3 = (Button)findViewById(R.id.button3); 
    button3.setText(buttonLabels[2]); 
    button3.setOnClickListener(this); 

    Button button4 = (Button)findViewById(R.id.button4); 
    button4.setText(buttonLabels[3]); 
    button4.setOnClickListener(this); 

    Button button5 = (Button)findViewById(R.id.button5); 
    button5.setText(buttonLabels[4]); 
    button5.setOnClickListener(this); 

    Button button6 = (Button)findViewById(R.id.button6); 
    button6.setText(buttonLabels[5]); 
    button6.setOnClickListener(this); 
} 

// Launch the phone dialer 

public void launchDialer(String number){ 
    String numberToDial = "tel:"+number; 
    startActivity(new Intent(Intent.ACTION_DIAL, Uri.parse(numberToDial))); 
} 


/** Method to populate the data arrays */ 

public void populateArrays(){ 

    /** In a practical application the arrays phoneNum and buttonLabels could be 
    * updated dynamically from the Web in this method. For this project we just 
    * hard-wire in some values to illustrate how to use such data, once obtained, 
    * to make phone calls.*/ 

    phoneNum[0] = "000-000-0001"; 
    phoneNum[1] = "000-000-0002"; 
    phoneNum[2] = "000-000-0003"; 
    phoneNum[3] = "000-000-0004"; 
    phoneNum[4] = "000-000-0005"; 
    phoneNum[5] = "000-000-0006"; 

    buttonLabels[0] = "Jane D. Arc"; 
    buttonLabels[1] = "John Doe"; 
    buttonLabels[2] = "Jane Doe"; 
    buttonLabels[3] = "Abe Linking"; 
    buttonLabels[4] = "Mona Liza"; 
    buttonLabels[5] = "Issac Nuton"; 
} 

/** Process button events */ 

@Override 
public void onClick(View v) { 
    switch (v.getId()) { 

     case R.id.button1: 
      launchDialer(phoneNum[0]); 
      break; 

     case R.id.button2: 
      launchDialer(phoneNum[1]); 
      break; 

     case R.id.button3: 
      launchDialer(phoneNum[2]); 
      break; 

     case R.id.button4: 
      launchDialer(phoneNum[3]); 
      break; 

     case R.id.button5: 
      launchDialer(phoneNum[4]); 
      break; 

     case R.id.button6: 
      launchDialer(phoneNum[5]); 
      break; 

    } 
} 

onStart()을 덮어 쓰려고하면 응용 프로그램이 충돌합니다. 당신은 그냥 작동 AdMob을 얻으려고 노력하는 경우

public void onStart(){ 
+0

나는 정말로 이해하지 못한다. "public void onStart() {"행에 @Override를 넣으려고합니까? – sabadow

+0

예. 문제는, 내가 코드를 하나 하나 넣을 때, 앱의 dosent가 충돌하지만, 두 블록을 넣을 때 앱이 충돌합니다. – user1427211

+0

충돌에 대한 스택 추적을 제공 할 수 있습니까? –

답변

1

, 당신은 ONSTART 사용하지 않아야합니다 :

public void onStart(){ 
    super.onStart(); 
    AdView layout = (AdView)this.findViewById(R.id.adView); 
    // Initiate a generic request to load it with an ad 
    AdRequest adRequest = new AdRequest(); 
    adRequest.setTesting(true); 
    layout.loadAd(adRequest); 
} 

나는 문제가이 선 것을 알고있다. 대신 onCreate를 사용하십시오.

아래에 Google Admob documentation에 있습니다. com.google.ads.AdView 섹션을 추가하십시오.

XML에 AdView가있는 경우 가져 와서 AdRequest를로드 할 수 있습니다. 그렇지 않은 경우 문서의 예는 동적으로 문서의 예제를 추가합니다.

또한 .destroy();를 호출해야합니다. 뷰에서 onDestroy 함수를 재정의해야 할 것입니다. 문서의 예문에 모두 나와 있습니다.

+0

아니 anwsers, 그냥 편집이야 .. 어머나 !!!! – user1427211