Thursday 15 July 2010

android - Launch new activity with spinner using Submit button -


I have a spinner that launches the activity, when it is automatically selected, how do I get a submit button , So that users can first select the activity they want to launch, and then tap submit to go to the selected screen? What I currently have:

  Private Spinner Spinner; @ Override Protected Zero (InstanceStat saved from bundle) {Log D. ("Test", "this is a test"); Super.onCreate (savedInstanceState); SetContentView (R.layout.activity_main); Spinner = (Spinner) Find VVBID (RID Spinner 1); ArrayAdapter & LT; CharSequence & gt; Adapter = Arrayadaptor.centformersource (it, R. night entries, AndroidRealt.Simple_spinner_dropdown_item); Adapter.setDropDownViewResource (android.R.layout.simple_spinner_dropdown_item); Spinner.setAdapter (adapter); Spinner.setOnItemSelectedListener (new function ()); } The function of the public square is selected from the Owner of Onomatium {@Override Selected items on Public Zero (see AdapterView & Lt;? & Gt; parent, AGR1, int PASS, long ID) {string selection = (TextView) arg1) .gettext () ToString (); If (Selection Angle ("red screen")) {intent intention = new intent (arg1.getContext (), display activation class); StartActivity; } And if (selection. Par ("Math Screen")) {intent intention = new intent (arg1.getContext (), number. Square); StartActivity; } Other {intention intended = new intent (arg1.getContext (), face. Class); StartActivity; }    

Try it out:

  Private Class Activity Device ; Private spinner spinner; Private button button; @ Override protected void saved create (bundled Instansstet) {Suprknkret (saved Instensstet); SetContentView (R.layout.activity_main); Spinner = (Spinner) Find VVBID (RID Spinner 1); Button = (button) Find VVBIID (RID button); ArrayAdapter & LT; CharSequence & gt; Adapter = Arrayadaptor.centformersource (it, R. night entries, AndroidRealt.Simple_spinner_dropdown_item); Adapter.setDropDownViewResource (android.R.layout.simple_spinner_dropdown_item); Spinner.setAdapter (adapter); Spinner.setOnItemSelectedListener (new function ()); Button. On the SoulClicklist list (see the new OnClickListener) click on {@Override Public Zero (click View) {if (activityToOpen! = Null) {intent = new intent (see .getContext (), activity usage); StartActivity;}}); } The function of the public class is selected from the Onistam Lister {@Override Pure Zero on the item selected (AdapterView & Lt;? & Gt; parent, agro 1, int pose, long id) {string selection = (TextView arg1) .gettext () ToString (); If (selection.equals ("red screen")) {activityToOpen = DisplayMessageActivity.class; } And if (Selection Engels ("Math Screen")) {activityToOpen = Numbers.class; } And {activityToOpen = Face.class; }   

Good luck.

No comments:

Post a Comment