time: 2015-06-13,14 graduated from the present, the work is almost a year, although in this year are engaged in the work of Android development, during the period also learned a lot of things, the industry has a more in-depth understanding, To a lot of basic knowledge points have also been consolidated and improved, the network communication has not been contacted also have a certain touch and grasp, overall, this year, there are many, growth is quite obvious. But a year ago to set their own goals (intermediate engineers) have a certain distance, not able to complete such a metamorphosis, so this time is trying to improve their development skills, the previous few days also considered the past training institutions to accept the system of learning, but listened to the suggestions of predecessors, They feel that training institutions are more targeted to those who are not working or are not in the Android development industry, that is, the purpose of training is more in favor of employment, rather than the improvement of substantive development ability, so abandoned the idea; under the guidance of a predecessor, First of all, by writing 100 lines of the actual code to improve their own coding ability, quality, specifications, predecessors suggested the original text as follows:
Recent projects require a checkbox to be used with Spinner, a checkbox for channel selection, and Spinner for parameter selection of selected channels, mainly involving two knowledge points:
1.CheckBox selection or not judgment;
2. Obtain the spinner parameter value corresponding to the selected checkbox;
First look at the layout: very simple, just a few components.
Then take a look at the implementation code:
1 PackageCom.example.threadandtasks;2 3 ImportAndroid.os.Bundle;4 Importandroid.app.Activity;5 ImportAndroid.util.Log;6 ImportAndroid.view.Menu;7 ImportAndroid.view.View;8 ImportAndroid.view.View.OnClickListener;9 ImportAndroid.widget.ArrayAdapter;Ten ImportAndroid.widget.Button; One ImportAndroid.widget.CheckBox; A ImportAndroid.widget.CompoundButton; - ImportAndroid.widget.Toast; - ImportAndroid.widget.CompoundButton.OnCheckedChangeListener; the ImportAndroid.widget.Spinner; - /** - * CheckBox - * + * Spinner - * + * Mixed Use A * at * 2015-06-09 - * */ - Public classMainactivityextendsActivity { - PublicCheckBox Cb_channeal1, Cb_channeal2; - PublicSpinner Spinner_channeal1, Spinner_channeal2; - PublicSpinner spinner_channeal11, spinner_channeal21; in Public Static FinalString[] M_arr = {"1000", "2000", "3000"}; - PublicButton Btn_data; to Public int[] Command = {0x12,0x33,0x44,0x45}; + - @Override the protected voidonCreate (Bundle savedinstancestate) { * Super. OnCreate (savedinstancestate); $ Setcontentview (r.layout.activity_main);Panax Notoginseng Initview (); - Checkboxlistener (); the } + A Public voidInitview () { theCb_channeal1 =(CheckBox) Findviewbyid (R.ID.CB_CHANNEL1); +Spinner_channeal1 =(Spinner) Findviewbyid (R.ID.SPINNER_CHANNEL1); -Spinner_channeal11 =(Spinner) Findviewbyid (R.ID.SPINNER_CHANNEL11); $Cb_channeal2 =(CheckBox) Findviewbyid (R.ID.CB_CHANNEL2); $Spinner_channeal2 =(Spinner) Findviewbyid (R.ID.SPINNER_CHANNEL2); -Spinner_channeal21 =(Spinner) Findviewbyid (R.ID.SPINNER_CHANNEL21); - theArrayadapter<string> Spinneradapter =NewArrayadapter<string> ( This, Android. R.layout.simple_spinner_item,m_arr); -Spinneradapter.setdropdownviewresource (Android. R.layout.simple_spinner_dropdown_item);//set the layout of the popup itemWuyi the Spinner_channeal1.setadapter (spinneradapter); - Spinner_channeal11.setadapter (spinneradapter); Wu Spinner_channeal2.setadapter (spinneradapter); - Spinner_channeal21.setadapter (spinneradapter); About $Btn_data =(Button) Findviewbyid (r.id.button1); -Btn_data.setonclicklistener (NewOnclicklistener () { - - @Override A Public voidOnClick (View arg0) { + //TODO Auto-generated method stubs the } - $ }); the } the the Public voidCheckboxlistener () { the Cb_channeal1.setoncheckedchangelistener (checkboxlistener); - Cb_channeal2.setoncheckedchangelistener (checkboxlistener); in } the PublicOncheckedchangelistener Checkboxlistener = (NewOncheckedchangelistener () { the About @Override the Public voidOnCheckedChanged (Compoundbutton arg0,BooleanisChecked) { the //TODO Auto-generated method stubs the Switch(Arg0.getid ()) { + Caser.id.cb_channel1:{ - if(isChecked) { theToast.maketext (Getapplicationcontext (), "0 isChecked", 555)Bayi . Show (); the}Else { theToast.maketext (Getapplicationcontext (), "0 is not Checked", -555). Show (); - } the}; Break; the Caser.id.cb_channel2:{ the if(isChecked) { theToast.maketext (Getapplicationcontext (), "1 isChecked", 555) - . Show (); the}Else { theToast.maketext (Getapplicationcontext (), "1 is not Checked", the555). Show ();94 } the}; Break; the the 98 }; About - }101 102 });103}
Android "Hundred yards" 1--checkbox, spinner with use