2011-09-12 98 views
0
Button createEventButton = (Button)findViewById(R.id.NewEventButton); 

Button createPageButton = (Button)findViewById(R.id.NewPageButton); 

Hallo 我已經遍尋搜索,但我沒有得到它。我是否應該將「NewEventButton」更改爲「button01」之類的內容。 問題是,如果我改變它,它停止工作的按鈕,正常按鈕時,它會打開手機瀏覽器並導航到一個網站。Android Google Analytics(R.id)重命名按鈕

同樣的情況發生在「NewPageButton」,eclipse也要求改變爲「button01」。

如果我離開他們,因爲它是,我有一個像「不能解析或不是場」

在此先感謝

UPDATE 這就是主要的XML文件,

錯誤
<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
android:background="@drawable/aevbackground" 
android:id="@+id/main" 
    > 

    <Button android:text="Other" android:id="@+id/button9" android:layout_width="wrap_content" android:layout_height="33dp" 
android:onClick="myonclick1" android:layout_gravity="bottom|right"></Button> 

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_gravity="center" 
    android:orientation="vertical"> 
    <TextView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello1" 
    /> 

<Button android:text="Home" android:id="@+id/button01" android:layout_width="230dp" android:layout_height="34dp" 
android:onClick="openBrowser1"></Button> 
<Button android:text="Forum" android:id="@+id/button2" android:layout_width="210dp" android:layout_height="34dp" 
android:onClick="openBrowser2"></Button> 
<Button android:text="FOC" android:id="@+id/button3" android:layout_width="190dp" android:layout_height="34dp" 
android:onClick="openBrowser3"></Button> 
<Button android:text="ON TFC" android:id="@+id/button4" android:layout_width="170dp" android:layout_height="34dp" 
android:onClick="openBrowser4"></Button> 
<Button android:text="At Facebook" android:id="@+id/button5" android:layout_width="150dp" android:layout_height="34dp" 
android:onClick="openBrowser5"></Button> 
<Button android:text="At Twitter" android:id="@+id/button6" android:layout_width="130dp" android:layout_height="34dp" 
android:onClick="openBrowser6"></Button> 
<Button android:text="At Google+" android:id="@+id/button7" android:layout_width="110dp" android:layout_height="34dp" 
android:onClick="openBrowser7"></Button>  
<Button android:text="@string/linkEmail" android:id="@+id/button8" android:layout_width="90dp" android:layout_height="34dp" 
android:onClick="linkEmailClicked"></Button> 

</LinearLayout> 

</FrameLayout> 

那是與谷歌分析主要的Java文件

package com.av0001; 


import com.google.android.apps.analytics.GoogleAnalyticsTracker; 

import android.app.Activity; 
import android.content.Intent; 
import android.net.Uri; 
import android.os.Bundle; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 
import android.widget.Toast; 

public class Main extends Activity { 
    /** Called when the activity is first created. */ 

    GoogleAnalyticsTracker tracker; 


    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     tracker = GoogleAnalyticsTracker.getInstance(); 
    // Start the tracker in manual dispatch mode... 
     tracker.startNewSession("UA-25624837-1", this); 
     setContentView(R.layout.main); 

     Button createEventButton = (Button)findViewById(R.id.button01); 
     createEventButton.setOnClickListener(new OnClickListener() { 
      @Override 
      public void onClick(View v) { 
      tracker.trackEvent(
       "Clicks", // Category 
       "Button", // Action 
       "clicked", // Label 
       77);  // Value 
      } 
     }); 

     Button createPageButton = (Button)findViewById(R.id.button01); 
     createPageButton.setOnClickListener(new OnClickListener() { 
      @Override 
      public void onClick(View v) { 
      // Add a Custom Variable to this pageview, with name of "Medium" and value "MobileApp" and 
      // scope of session-level. 
      tracker.setCustomVar(1, "Navigation Type", "Button click", 2); 
      // Track a page view. This is probably the best way to track which parts of your application 
      // are being used. 
      // E.g. 
      // tracker.trackPageView("/help"); to track someone looking at the help screen. 
      // tracker.trackPageView("/level2"); to track someone reaching level 2 in a game. 
      // tracker.trackPageView("/uploadScreen"); to track someone using an upload screen. 
      tracker.trackPageView("/mainspalsh"); 
      tracker.trackPageView("/main"); 
      tracker.trackPageView("/main2"); 
      tracker.trackPageView("/main3"); 

      } 
     }); 

     Button quitButton = (Button)findViewById(R.id.button01); 
     quitButton.setOnClickListener(new OnClickListener() { 
      @Override 
      public void onClick(View v) { 
      finish(); 
      } 
     }); 

     Button dispatchButton = (Button)findViewById(R.id.button01); 
     dispatchButton.setOnClickListener(new OnClickListener() { 
      @Override 
      public void onClick(View v) { 
      // Manually start a dispatch, not needed if the tracker was started with a dispatch 
      // interval. 
      tracker.dispatch(); 
      } 
     }); 
     } 
     public void openBrowser1(View view) { 
      Intent i = new Intent("android.intent.action.VIEW", Uri.parse("")); 
      startActivity(i); 
     } 
     public void openBrowser2(View view) { 
      Intent i = new Intent("android.intent.action.VIEW", Uri.parse("")); 
      startActivity(i); 
     } 
     public void openBrowser3(View view) { 
      Intent i = new Intent("android.intent.action.VIEW", Uri.parse("")); 
      startActivity(i); 
     } 
     public void openBrowser4(View view) { 
      Intent i = new Intent("android.intent.action.VIEW", Uri.parse("")); 
      startActivity(i); 
     } 
     public void openBrowser5(View view) { 
      Intent i = new Intent("android.intent.action.VIEW", Uri.parse("")); 
      startActivity(i);  
     } 
     public void openBrowser6(View view) { 
      Intent i = new Intent("android.intent.action.VIEW", Uri.parse("")); 
      startActivity(i); 
     } 
     public void openBrowser7(View view) { 
      Intent i = new Intent("android.intent.action.VIEW", Uri.parse("")); 
      startActivity(i); 
     } 
     public void linkEmailClicked(View v) { 
      Intent it = new Intent(Intent.ACTION_SEND); 
      String[] tos = {getString(R.string.emailAddress)}; 
      it.putExtra(Intent.EXTRA_EMAIL, tos); 
      it.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.emailSubject)); 
      it.setType("text/plain"); 
      startActivity(it); 
     } 
     public void myonclick1(View view) { 
      Intent mIntent = new Intent(this,Main2.class); 
      startActivity(mIntent); 
      Toast.makeText(
        this, 
        "Thank you for using xxxxxxxxxxxxxxxxxxxxxx application, enjoy browsing :)", Toast.LENGTH_LONG).show(); 
      finish(); 
     } 
      @Override 
      protected void onStart() { 
       super.onStart(); 
       // The activity is about to become visible. 
      } 
      @Override 
      protected void onResume() { 
       super.onResume(); 
       // The activity has become visible (it is now "resumed"). 
      } 
      @Override 
      protected void onPause() { 
       super.onPause(); 
       // Another activity is taking focus (this activity is about to be "paused"). 
      } 
      @Override 
      protected void onStop() { 
       super.onStop(); 
       // The activity is no longer visible (it is now "stopped") 
      } 
      @Override 
      protected void onDestroy() { 
       super.onDestroy(); 
       // The activity is about to be destroyed. 
      // Stop the tracker when it is no longer needed. 
       tracker.stopSession(); 
      } 
     } 
+0

顯示您的活動的全部代碼。 – user370305

+0

清理你的代碼可能是?項目 - >清潔 –

+1

您應該爲您的問題使用有意義的標題 – aromero

回答

1

聽起來我在重命名它,但沒有更改XML佈局ID名稱,因此R.java沒有新名稱。如果您也在更改XML,那麼您不會重新編譯該項目。確保在Eclipse環境中選擇自動編譯。轉到項目 - >自動生成,並確保它旁邊有複選標記。

----備用建議---- 您使用的是什麼版本的eclipse和ADB ...您可能需要升級到最新版本並重新安裝ADB ....我有類似的編譯錯誤,只有升級和重新安裝工作。你的代碼爲我編譯好。不知道你將如何達到這些方法中的一部分,並且你有4個聽衆正在聽同一個按鈕R.id.button01。下面是我在Eclipse中運行代碼:

enter image description here

+0

對不起,但我不明白,因爲我問,我應該保持原樣,還是換成「button01」。這個「自動編譯」設置在哪裏,我找不到它,謝謝。 – Christopher

+0

你可以爲你的按鈕ID名稱想要任何名稱......只需確保在layout.xml代碼中更改id =「+ id/yourname」。然後改變對它的引用。 – JPM

+1

太好了,這很清楚。謝謝 – Christopher