我是新手在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
不是你得到像「複製方法的onCreate()式HomeActivity」 – 2014-02-16 06:26:03