已经存在具有相同签名的另一种方法

时间:2014-02-16 06:20:33

标签: java android

我是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.

抱歉我的英语不好。 感谢您的答复。 此致

2 个答案:

答案 0 :(得分:1)

您在同一个活动中有2个onCreate个功能。你只能有一个。这就是为什么它抱怨已经有一个具有相同签名的方法。删除其中一个并将其中的一个移动到另一个。正如@Ravn在评论中所提到的,你可以拥有多个具有相同名称但具有不同参数的函数。

答案 1 :(得分:0)

你不能拥有两次相同签名的方法

@Override
public void onCreate(Bundle savedInstanceState)

@Override
public void onCreate(Bundle b)