2014-02-16 113 views
0

我是新手在android編程,然後我有一個問題,以整合一部分代碼。已經有另一種方法具有相同的簽名

public class HomeActivity extends SherlockFragmentActivity 
implements ActionBar.OnNavigationListener, VideoListFragment.OnVideoSelectedListener{ 


// create object of ActionBar and VideoListFragment 
ActionBar actionbar; 
VideoListFragment videoListFrag; 

int selectedItem; 

private AdController ad; 


@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_home); 

    // add channel list array to actionbar spinner 
    Context context = getSupportActionBar().getThemedContext(); 
    ArrayAdapter<CharSequence> list = ArrayAdapter.createFromResource(context, R.array.channel_name, R.layout.sherlock_spinner_item); 
    list.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item); 

    // remove actionbar title and add spinner to actionbar 
    getSupportActionBar().setDisplayShowTitleEnabled(false); 
    getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); 
    getSupportActionBar().setListNavigationCallbacks(list, this); 
} 

// create option menu 
public boolean onCreateOptionsMenu(Menu menu) { 
    getSupportMenuInflater().inflate(R.menu.home, menu); 
    return true; 
} 

// listener for option menu 
@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    switch (item.getItemId()) { 
     case R.id.menuShare: 
      // share google play link of this app to other app such as email, facebook, etc 
      Intent iShare = new Intent(Intent.ACTION_SEND); 
      iShare.setType("text/plain"); 
      iShare.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.subject)); 
      iShare.putExtra(Intent.EXTRA_TEXT, getString(R.string.message)+" "+getString(R.string.gplay_web_url)); 
      startActivity(Intent.createChooser(iShare, getString(R.string.share_via))); 
      return true; 
     case R.id.menuRate: 
      // open google play app to ask user to rate & review this app 
      Intent iRate = new Intent(Intent.ACTION_VIEW); 
      iRate.setData(Uri.parse(getString(R.string.gplay_url))); 
      startActivity(iRate); 
      return true; 
     case R.id.menuAbout: 
      // open About app page 
      Intent iAbout = new Intent(this, AboutActivity.class); 
      startActivity(iAbout); 
      return true; 
     default: 
      return super.onOptionsItemSelected(item); 
    } 
} 

@Override 
public boolean onNavigationItemSelected(int itemPosition, long itemId) { 
    // TODO Auto-generated method stub 

    selectedItem = itemPosition; 

    // create object of VideoListFragment and send data position to that fragment 
    videoListFrag = new VideoListFragment(); 
    Bundle bundle = new Bundle(); 
    bundle.putInt("position", itemPosition); 
    videoListFrag.setArguments(bundle); 

    // call video list fragment with new data 
    getSupportFragmentManager() 
    .beginTransaction() 
    .replace(R.id.content_frame, videoListFrag, "VIDEO_LIST_FRAGMENT") 
    .commit(); 
    return true; 
} 

@Override 
public void onVideoSelected(String ID) { 
    // TODO Auto-generated method stub 

    // call player page to play selected video 
    Intent i = new Intent(this, PlayerActivity.class); 
    i.putExtra("id", ID); 
    startActivity(i); 

} 




@Override 
public void onCreate(Bundle b) { 
    super.onCreate(b); 
    setContentView(R.layout.activity_home); 

    ad = new AdController(this, "MY_LB_SECTION_ID"); 
    ad.loadStartAd("MY_LB_AUDIO_ID", "MY_LB_REENGAGEMENT_ID"); 
    AppTracker.startSession(this, "APPFIREWORKS_API_KEY"); 
} 
@Override 
    public void onPause() { super.onPause(); 
    if(ad != null) { ad.destroyAd(); 
    } if(!isFinishing()) { AppTracker.pause(getApplicationContext()); 
    } } 
@Override 
    public void onResume() { super.onResume(); 
    AppTracker.resume(getApplicationContext()); 
} 
@Override 
public void onDestroy() { super.onDestroy(); 
    if(ad != null) { ad.destroyAd(); 
    } AppTracker.closeSession(getApplicationContext(),true); 
} 
} 


The problem is on on create. 

對不起,我的英語不好。 感謝您的回覆。 Regards

+2

不是你得到像「複製方法的onCreate()式HomeActivity」 – 2014-02-16 06:26:03

回答

1

在同一活動中有2個onCreate函數。你只能有一個。這就是爲什麼它抱怨已經有一個簽名相同的方法。刪除其中的一個並將其中的內容從一個移動到另一個。正如@Ravn在評論中提到的那樣,你可以有多個具有相同名稱但具有不同參數的函數。

+2

任何錯誤方法,你可以有幾個,但他們需要有不同的參數(參數_types_準確)。 –

0

不能有相同的簽名兩次

@Override 
public void onCreate(Bundle savedInstanceState) 

@Override 
public void onCreate(Bundle b) 
相關問題