Where to write java code in Android app -
i started learning how create android app , i'm stuck methods in mainactivity.java. don't know write java code because app crashing.
package com.cidecode.loveometer; public class mainactivity extends actionbaractivity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); if (savedinstancestate == null) { getsupportfragmentmanager().begintransaction() .add(r.id.container, new placeholderfragment()) .commit(); } } @override public boolean oncreateoptionsmenu(menu menu) { getmenuinflater().inflate(r.menu.main, menu); return true; } @override public boolean onoptionsitemselected(menuitem item) { int id = item.getitemid(); if (id == r.id.action_settings) { return true; } return super.onoptionsitemselected(item); } public static class placeholderfragment extends fragment { public placeholderfragment() { } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view rootview = inflater.inflate(r.layout.fragment_main, container, false); return rootview; } } }
things want created when activity started should in oncreate method (buttons , onclicklisteners etc). if example have button have stated onclick name in xml file (rather put onclicklistener on it) can put function long not after last curly brace finishes activity. should try new boston tutorials on youtube, found explained lot , helped me understand needed put things.
Comments
Post a Comment