android第六次课 UI2设计.docx
《android第六次课 UI2设计.docx》由会员分享,可在线阅读,更多相关《android第六次课 UI2设计.docx(30页珍藏版)》请在冰点文库上搜索。
android第六次课UI2设计
第五次课UI
(2)
5.单选按钮RadioButton
RadioButton的单选按钮;
RadioGroup是单选组合框,用于将RadioButton框起来;
在没有RadioGroup的情况下,RadioButton可以全部都选中;
当多个RadioButton被RadioGroup包含的情况下,RadioButton只可以选择一个;
单选按钮的事件监听用setOnCheckedChangeListener来对单选按钮进行监听
Strings.xml
xmlversion="1.0"encoding="utf-8"?
>
哪个城市叫做山城?
单选按钮测试
杭州
成都
重庆
苏州
Main.xml
android="android:layout_width="fill_parent"android:layout_height="fill_parent"android:orientation="vertical">android:id="@+id/textview1"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="@string/hello"android:textSize="20sp"/>android:id="@+id/radiogroup1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_x="3px"android:orientation="vertical">android:id="@+id/radiobutton1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/radiobutton1"/>android:id="@+id/radiobutton2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/radiobutton2"/>android:id="@+id/radiobutton3"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/radiobutton3"/>android:id="@+id/radiobutton4"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/radiobutton4"/> packagenynu.edu.sy;importandroid.app.Activity;importandroid.os.Bundle;importandroid.view.Gravity;importandroid.widget.RadioButton;importandroid.widget.RadioGroup;importandroid.widget.TextView;importandroid.widget.Toast;publicclassUisyActivityextendsActivity{TextViewtextview;RadioGroupradiogroup;RadioButtonradio1,radio2,radio3,radio4;publicvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.main);textview=(TextView)findViewById(R.id.textview1);radiogroup=(RadioGroup)findViewById(R.id.radiogroup1);radio1=(RadioButton)findViewById(R.id.radiobutton1);radio2=(RadioButton)findViewById(R.id.radiobutton2);radio3=(RadioButton)findViewById(R.id.radiobutton3);radio4=(RadioButton)findViewById(R.id.radiobutton4);radiogroup.setOnCheckedChangeListener(newRadioGroup.OnCheckedChangeListener(){publicvoidonCheckedChanged(RadioGroupgroup,intcheckedId){if(checkedId==radio3.getId()){DisplayToast("正确答案:"+radio2.getText()+",恭喜你,回答正确!");}else{DisplayToast("请注意,回答错误!");}}});}publicvoidDisplayToast(Stringstr){Toasttoast=Toast.makeText(this,str,Toast.LENGTH_LONG);toast.setGravity(Gravity.TOP,0,220);toast.show();}}6.CheckBox复选框多选按钮CheckBox的可以实现多项选择,我们可以现在布局文件中定义多选按钮,然后对每一个多选按钮进行事件监听setOnCheckedChangeListener,通过isChecked来判断选项是否被选中xmlversion="1.0"encoding="utf-8"?>调查:你喜欢Android的那款手机?CheckBoxTestHTCdesireHDGooglenexusoneHTCdefy摩托罗拉里程碑II xmlversion="1.0"encoding="utf-8"?>android="android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent">android:id="@+id/textview"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="@string/hello"android:textSize="20sp"/>android:id="@+id/checkbox1"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="@string/checkbox1"/>android:id="@+id/checkbox2"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="@string/checkbox2"/>android:id="@+id/checkbox3"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="@string/checkbox3"/>android:id="@+id/checkbox4"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="@string/checkbox4"/>android:id="@+id/submit"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="right"android:text="提交信息"/> packagenynu.edu.sy;importandroid.app.Activity;importandroid.os.Bundle;importandroid.view.Gravity;importandroid.view.View;importandroid.view.View.OnClickListener;importandroid.widget.CompoundButton;importandroid.widget.Button;importandroid.widget.CheckBox;importandroid.widget.RadioButton;importandroid.widget.RadioGroup;importandroid.widget.RadioGroup.OnCheckedChangeListener;importandroid.widget.TextView;importandroid.widget.Toast;publicclassTextViewSyActivityextendsActivity{/**Calledwhentheactivityisfirstcreated.*/privateTextViewtextview;privateButtonsubmit;privateCheckBoxcheckbox1,checkbox2,checkbox3,checkbox4;privateStrings=null; @OverridepublicvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.main);textview=(TextView)findViewById(R.id.textview);submit=(Button)findViewById(R.id.submit);submit.setOnClickListener(newOnClickbt());//取得每一个CheckBox对象checkbox1=(CheckBox)findViewById(R.id.checkbox1);checkbox2=(CheckBox)findViewById(R.id.checkbox2);checkbox3=(CheckBox)findViewById(R.id.checkbox3);checkbox4=(CheckBox)findViewById(R.id.checkbox4);//为每一个选项设置监听checkbox1.setOnCheckedChangeListener(newOnCheckchange());checkbox2.setOnCheckedChangeListener(newOnCheckchange());checkbox3.setOnCheckedChangeListener(newOnCheckchange());checkbox4.setOnCheckedChangeListener(newOnCheckchange());}privateclassOnCheckchangeimplementsCheckBox.OnCheckedChangeListener{publicvoidonCheckedChanged(CompoundButtonbuttonView,booleanisChecked){if(checkbox1.isChecked())s=s+checkbox1.getText()+"";elseif(checkbox2.isChecked())s=s+checkbox2.getText()+"";elseif(checkbox3.isChecked())s=s+checkbox3.getText()+"";elseif(checkbox4.isChecked())s=s+checkbox4.getText()+"";}}privateclassOnClickbtimplementsOnClickListener{publicvoidonClick(Viewv){DisplayToast(s);}}publicvoidDisplayToast(Stringstr){Toasttoast=Toast.makeText(this,str,Toast.LENGTH_SHORT);//设置Toast的显示位置toast.setGravity(Gravity.TOP,0,220);//显示Toasttoast.show();}}7.下拉列表框Spinner1)采用xml建立下拉列表数据,setOnItemSelectedListener进行监听。在values下建立intersts.xml,存放下拉列表的数据内容xmlversion="1.0"encoding="utf-8"?>篮球排球足球strings.xmlxmlversion="1.0"encoding="utf-8"?>HelloWorld,Activity01!xh_spinner_test您喜欢的球类运动是:main.xmlxmlversion="1.0"encoding="utf-8"?>android="android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent">android:text="@string/ys"android:id="@+id/TextView01"android:layout_width="fill_parent"android:layout_height="wrap_content"android:textSize="20sp"/>android:id="@+id/instersting"android:layout_width="fill_parent"android:layout_height="wrap_content"android:entries="@array/interestsdata"/>Java程序packagenynu.edu.sy;importandroid.app.Activity;importandroid.os.Bundle;importandroid.view.View;importandroid.widget.AdapterView;importandroid.widget.AdapterView.OnItemSelectedListener;importandroid.widget.ArrayAdapter;importandroid.widget.Spinner;importandroid.widget.TextView;importandroid.widget.Toast;publicclassUisyActivityextendsActivity{privateSpinnerinterestspinner=null;privateTextViewinfo=null;protectedvoidonCreate(BundlesavedInstanceState){//TODOAuto-generatedmethodstubsuper.onCreate(savedInstanceState);this.setContentView(R.layout.main);interestspinner=(Spinner)this.findViewById(R.id.instersting);info=(TextView)this.findViewById(R.id.TextView01);interestspinner.setOnItemSelectedListener(newnItemSelectedListenerImp());}privateclassnItemSelectedListenerImpimplementsOnItemSelectedListener{publicvoidonItemSelected(AdapterView>arg0,Viewarg1,intarg2,longarg3){//TODOAuto-generatedmethodstubStringvalues=arg0.getItemAtPosition(arg2).toString();Toast.makeText(UisyActivity.this,"您喜欢的球类运动是:"+values,1).show();}publicvoidonNothingSelected(AdapterView>arg0){//TODOAuto-generatedmethodstub}}}2)首先需要在布局中定时Spinner组件,然后将可选内容通过ArrayAdapter和下拉列表连接起来,最后要获得用户选择的选项,设计事件监听器setOnItemSelectedListener并实现onItemSelected,从而获得用户所选择的内容,最后通过setVisibility方法设置当前的显示项xmlversion="1.0"encoding="utf-8"?>android="android:orientation="vertical"android:layout_width="fill_parent"android:layout_heig
android="
android:
layout_width="fill_parent"
layout_height="fill_parent"
orientation="vertical">
android:id="@+id/textview1"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="@string/hello"android:textSize="20sp"/>android:id="@+id/radiogroup1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_x="3px"android:orientation="vertical">android:id="@+id/radiobutton1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/radiobutton1"/>android:id="@+id/radiobutton2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/radiobutton2"/>android:id="@+id/radiobutton3"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/radiobutton3"/>android:id="@+id/radiobutton4"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/radiobutton4"/> packagenynu.edu.sy;importandroid.app.Activity;importandroid.os.Bundle;importandroid.view.Gravity;importandroid.widget.RadioButton;importandroid.widget.RadioGroup;importandroid.widget.TextView;importandroid.widget.Toast;publicclassUisyActivityextendsActivity{TextViewtextview;RadioGroupradiogroup;RadioButtonradio1,radio2,radio3,radio4;publicvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.main);textview=(TextView)findViewById(R.id.textview1);radiogroup=(RadioGroup)findViewById(R.id.radiogroup1);radio1=(RadioButton)findViewById(R.id.radiobutton1);radio2=(RadioButton)findViewById(R.id.radiobutton2);radio3=(RadioButton)findViewById(R.id.radiobutton3);radio4=(RadioButton)findViewById(R.id.radiobutton4);radiogroup.setOnCheckedChangeListener(newRadioGroup.OnCheckedChangeListener(){publicvoidonCheckedChanged(RadioGroupgroup,intcheckedId){if(checkedId==radio3.getId()){DisplayToast("正确答案:"+radio2.getText()+",恭喜你,回答正确!");}else{DisplayToast("请注意,回答错误!");}}});}publicvoidDisplayToast(Stringstr){Toasttoast=Toast.makeText(this,str,Toast.LENGTH_LONG);toast.setGravity(Gravity.TOP,0,220);toast.show();}}6.CheckBox复选框多选按钮CheckBox的可以实现多项选择,我们可以现在布局文件中定义多选按钮,然后对每一个多选按钮进行事件监听setOnCheckedChangeListener,通过isChecked来判断选项是否被选中xmlversion="1.0"encoding="utf-8"?>调查:你喜欢Android的那款手机?CheckBoxTestHTCdesireHDGooglenexusoneHTCdefy摩托罗拉里程碑II xmlversion="1.0"encoding="utf-8"?>android="android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent">android:id="@+id/textview"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="@string/hello"android:textSize="20sp"/>android:id="@+id/checkbox1"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="@string/checkbox1"/>android:id="@+id/checkbox2"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="@string/checkbox2"/>android:id="@+id/checkbox3"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="@string/checkbox3"/>android:id="@+id/checkbox4"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="@string/checkbox4"/>android:id="@+id/submit"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="right"android:text="提交信息"/> packagenynu.edu.sy;importandroid.app.Activity;importandroid.os.Bundle;importandroid.view.Gravity;importandroid.view.View;importandroid.view.View.OnClickListener;importandroid.widget.CompoundButton;importandroid.widget.Button;importandroid.widget.CheckBox;importandroid.widget.RadioButton;importandroid.widget.RadioGroup;importandroid.widget.RadioGroup.OnCheckedChangeListener;importandroid.widget.TextView;importandroid.widget.Toast;publicclassTextViewSyActivityextendsActivity{/**Calledwhentheactivityisfirstcreated.*/privateTextViewtextview;privateButtonsubmit;privateCheckBoxcheckbox1,checkbox2,checkbox3,checkbox4;privateStrings=null; @OverridepublicvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.main);textview=(TextView)findViewById(R.id.textview);submit=(Button)findViewById(R.id.submit);submit.setOnClickListener(newOnClickbt());//取得每一个CheckBox对象checkbox1=(CheckBox)findViewById(R.id.checkbox1);checkbox2=(CheckBox)findViewById(R.id.checkbox2);checkbox3=(CheckBox)findViewById(R.id.checkbox3);checkbox4=(CheckBox)findViewById(R.id.checkbox4);//为每一个选项设置监听checkbox1.setOnCheckedChangeListener(newOnCheckchange());checkbox2.setOnCheckedChangeListener(newOnCheckchange());checkbox3.setOnCheckedChangeListener(newOnCheckchange());checkbox4.setOnCheckedChangeListener(newOnCheckchange());}privateclassOnCheckchangeimplementsCheckBox.OnCheckedChangeListener{publicvoidonCheckedChanged(CompoundButtonbuttonView,booleanisChecked){if(checkbox1.isChecked())s=s+checkbox1.getText()+"";elseif(checkbox2.isChecked())s=s+checkbox2.getText()+"";elseif(checkbox3.isChecked())s=s+checkbox3.getText()+"";elseif(checkbox4.isChecked())s=s+checkbox4.getText()+"";}}privateclassOnClickbtimplementsOnClickListener{publicvoidonClick(Viewv){DisplayToast(s);}}publicvoidDisplayToast(Stringstr){Toasttoast=Toast.makeText(this,str,Toast.LENGTH_SHORT);//设置Toast的显示位置toast.setGravity(Gravity.TOP,0,220);//显示Toasttoast.show();}}7.下拉列表框Spinner1)采用xml建立下拉列表数据,setOnItemSelectedListener进行监听。在values下建立intersts.xml,存放下拉列表的数据内容xmlversion="1.0"encoding="utf-8"?>篮球排球足球strings.xmlxmlversion="1.0"encoding="utf-8"?>HelloWorld,Activity01!xh_spinner_test您喜欢的球类运动是:main.xmlxmlversion="1.0"encoding="utf-8"?>android="android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent">android:text="@string/ys"android:id="@+id/TextView01"android:layout_width="fill_parent"android:layout_height="wrap_content"android:textSize="20sp"/>android:id="@+id/instersting"android:layout_width="fill_parent"android:layout_height="wrap_content"android:entries="@array/interestsdata"/>Java程序packagenynu.edu.sy;importandroid.app.Activity;importandroid.os.Bundle;importandroid.view.View;importandroid.widget.AdapterView;importandroid.widget.AdapterView.OnItemSelectedListener;importandroid.widget.ArrayAdapter;importandroid.widget.Spinner;importandroid.widget.TextView;importandroid.widget.Toast;publicclassUisyActivityextendsActivity{privateSpinnerinterestspinner=null;privateTextViewinfo=null;protectedvoidonCreate(BundlesavedInstanceState){//TODOAuto-generatedmethodstubsuper.onCreate(savedInstanceState);this.setContentView(R.layout.main);interestspinner=(Spinner)this.findViewById(R.id.instersting);info=(TextView)this.findViewById(R.id.TextView01);interestspinner.setOnItemSelectedListener(newnItemSelectedListenerImp());}privateclassnItemSelectedListenerImpimplementsOnItemSelectedListener{publicvoidonItemSelected(AdapterView>arg0,Viewarg1,intarg2,longarg3){//TODOAuto-generatedmethodstubStringvalues=arg0.getItemAtPosition(arg2).toString();Toast.makeText(UisyActivity.this,"您喜欢的球类运动是:"+values,1).show();}publicvoidonNothingSelected(AdapterView>arg0){//TODOAuto-generatedmethodstub}}}2)首先需要在布局中定时Spinner组件,然后将可选内容通过ArrayAdapter和下拉列表连接起来,最后要获得用户选择的选项,设计事件监听器setOnItemSelectedListener并实现onItemSelected,从而获得用户所选择的内容,最后通过setVisibility方法设置当前的显示项xmlversion="1.0"encoding="utf-8"?>android="android:orientation="vertical"android:layout_width="fill_parent"android:layout_heig
id="@+id/textview1"
layout_height="wrap_content"
text="@string/hello"
textSize="20sp"/>
android:id="@+id/radiogroup1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_x="3px"android:orientation="vertical">android:id="@+id/radiobutton1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/radiobutton1"/>android:id="@+id/radiobutton2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/radiobutton2"/>android:id="@+id/radiobutton3"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/radiobutton3"/>android:id="@+id/radiobutton4"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/radiobutton4"/>
id="@+id/radiogroup1"
layout_width="wrap_content"
layout_x="3px"
android:id="@+id/radiobutton1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/radiobutton1"/>android:id="@+id/radiobutton2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/radiobutton2"/>android:id="@+id/radiobutton3"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/radiobutton3"/>android:id="@+id/radiobutton4"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/radiobutton4"/>
id="@+id/radiobutton1"
text="@string/radiobutton1"/>
android:id="@+id/radiobutton2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/radiobutton2"/>android:id="@+id/radiobutton3"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/radiobutton3"/>android:id="@+id/radiobutton4"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/radiobutton4"/>
id="@+id/radiobutton2"
text="@string/radiobutton2"/>
android:id="@+id/radiobutton3"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/radiobutton3"/>android:id="@+id/radiobutton4"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/radiobutton4"/>
id="@+id/radiobutton3"
text="@string/radiobutton3"/>
android:id="@+id/radiobutton4"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/radiobutton4"/>
id="@+id/radiobutton4"
text="@string/radiobutton4"/>
packagenynu.edu.sy;
importandroid.app.Activity;
importandroid.os.Bundle;
importandroid.view.Gravity;
importandroid.widget.RadioButton;
importandroid.widget.RadioGroup;
importandroid.widget.TextView;
importandroid.widget.Toast;
publicclassUisyActivityextendsActivity{
TextViewtextview;
RadioGroupradiogroup;
RadioButtonradio1,radio2,radio3,radio4;
publicvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
textview=(TextView)findViewById(R.id.textview1);
radiogroup=(RadioGroup)findViewById(R.id.radiogroup1);
radio1=(RadioButton)findViewById(R.id.radiobutton1);
radio2=(RadioButton)findViewById(R.id.radiobutton2);
radio3=(RadioButton)findViewById(R.id.radiobutton3);
radio4=(RadioButton)findViewById(R.id.radiobutton4);
radiogroup
.setOnCheckedChangeListener(newRadioGroup.OnCheckedChangeListener(){
publicvoidonCheckedChanged(RadioGroupgroup,intcheckedId){
if(checkedId==radio3.getId())
{
DisplayToast("正确答案:
"+radio2.getText()
+",恭喜你,回答正确!
");
}else
DisplayToast("请注意,回答错误!
}
});
publicvoidDisplayToast(Stringstr)
Toasttoast=Toast.makeText(this,str,Toast.LENGTH_LONG);
toast.setGravity(Gravity.TOP,0,220);
toast.show();
6.CheckBox复选框
多选按钮CheckBox的可以实现多项选择,我们可以现在布局文件中定义多选按钮,然后对每一个多选按钮进行事件监听
setOnCheckedChangeListener,通过isChecked来判断选项是否被选中
调查:
你喜欢Android的那款手机?
CheckBoxTest
HTCdesireHD
Googlenexusone
HTCdefy
摩托罗拉里程碑II
android="android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent">android:id="@+id/textview"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="@string/hello"android:textSize="20sp"/>android:id="@+id/checkbox1"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="@string/checkbox1"/>android:id="@+id/checkbox2"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="@string/checkbox2"/>android:id="@+id/checkbox3"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="@string/checkbox3"/>android:id="@+id/checkbox4"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="@string/checkbox4"/>android:id="@+id/submit"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="right"android:text="提交信息"/> packagenynu.edu.sy;importandroid.app.Activity;importandroid.os.Bundle;importandroid.view.Gravity;importandroid.view.View;importandroid.view.View.OnClickListener;importandroid.widget.CompoundButton;importandroid.widget.Button;importandroid.widget.CheckBox;importandroid.widget.RadioButton;importandroid.widget.RadioGroup;importandroid.widget.RadioGroup.OnCheckedChangeListener;importandroid.widget.TextView;importandroid.widget.Toast;publicclassTextViewSyActivityextendsActivity{/**Calledwhentheactivityisfirstcreated.*/privateTextViewtextview;privateButtonsubmit;privateCheckBoxcheckbox1,checkbox2,checkbox3,checkbox4;privateStrings=null; @OverridepublicvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.main);textview=(TextView)findViewById(R.id.textview);submit=(Button)findViewById(R.id.submit);submit.setOnClickListener(newOnClickbt());//取得每一个CheckBox对象checkbox1=(CheckBox)findViewById(R.id.checkbox1);checkbox2=(CheckBox)findViewById(R.id.checkbox2);checkbox3=(CheckBox)findViewById(R.id.checkbox3);checkbox4=(CheckBox)findViewById(R.id.checkbox4);//为每一个选项设置监听checkbox1.setOnCheckedChangeListener(newOnCheckchange());checkbox2.setOnCheckedChangeListener(newOnCheckchange());checkbox3.setOnCheckedChangeListener(newOnCheckchange());checkbox4.setOnCheckedChangeListener(newOnCheckchange());}privateclassOnCheckchangeimplementsCheckBox.OnCheckedChangeListener{publicvoidonCheckedChanged(CompoundButtonbuttonView,booleanisChecked){if(checkbox1.isChecked())s=s+checkbox1.getText()+"";elseif(checkbox2.isChecked())s=s+checkbox2.getText()+"";elseif(checkbox3.isChecked())s=s+checkbox3.getText()+"";elseif(checkbox4.isChecked())s=s+checkbox4.getText()+"";}}privateclassOnClickbtimplementsOnClickListener{publicvoidonClick(Viewv){DisplayToast(s);}}publicvoidDisplayToast(Stringstr){Toasttoast=Toast.makeText(this,str,Toast.LENGTH_SHORT);//设置Toast的显示位置toast.setGravity(Gravity.TOP,0,220);//显示Toasttoast.show();}}7.下拉列表框Spinner1)采用xml建立下拉列表数据,setOnItemSelectedListener进行监听。在values下建立intersts.xml,存放下拉列表的数据内容xmlversion="1.0"encoding="utf-8"?>篮球排球足球strings.xmlxmlversion="1.0"encoding="utf-8"?>HelloWorld,Activity01!xh_spinner_test您喜欢的球类运动是:main.xmlxmlversion="1.0"encoding="utf-8"?>android="android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent">android:text="@string/ys"android:id="@+id/TextView01"android:layout_width="fill_parent"android:layout_height="wrap_content"android:textSize="20sp"/>android:id="@+id/instersting"android:layout_width="fill_parent"android:layout_height="wrap_content"android:entries="@array/interestsdata"/>Java程序packagenynu.edu.sy;importandroid.app.Activity;importandroid.os.Bundle;importandroid.view.View;importandroid.widget.AdapterView;importandroid.widget.AdapterView.OnItemSelectedListener;importandroid.widget.ArrayAdapter;importandroid.widget.Spinner;importandroid.widget.TextView;importandroid.widget.Toast;publicclassUisyActivityextendsActivity{privateSpinnerinterestspinner=null;privateTextViewinfo=null;protectedvoidonCreate(BundlesavedInstanceState){//TODOAuto-generatedmethodstubsuper.onCreate(savedInstanceState);this.setContentView(R.layout.main);interestspinner=(Spinner)this.findViewById(R.id.instersting);info=(TextView)this.findViewById(R.id.TextView01);interestspinner.setOnItemSelectedListener(newnItemSelectedListenerImp());}privateclassnItemSelectedListenerImpimplementsOnItemSelectedListener{publicvoidonItemSelected(AdapterView>arg0,Viewarg1,intarg2,longarg3){//TODOAuto-generatedmethodstubStringvalues=arg0.getItemAtPosition(arg2).toString();Toast.makeText(UisyActivity.this,"您喜欢的球类运动是:"+values,1).show();}publicvoidonNothingSelected(AdapterView>arg0){//TODOAuto-generatedmethodstub}}}2)首先需要在布局中定时Spinner组件,然后将可选内容通过ArrayAdapter和下拉列表连接起来,最后要获得用户选择的选项,设计事件监听器setOnItemSelectedListener并实现onItemSelected,从而获得用户所选择的内容,最后通过setVisibility方法设置当前的显示项xmlversion="1.0"encoding="utf-8"?>android="android:orientation="vertical"android:layout_width="fill_parent"android:layout_heig
orientation="vertical"
android:id="@+id/textview"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="@string/hello"android:textSize="20sp"/>android:id="@+id/checkbox1"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="@string/checkbox1"/>android:id="@+id/checkbox2"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="@string/checkbox2"/>android:id="@+id/checkbox3"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="@string/checkbox3"/>android:id="@+id/checkbox4"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="@string/checkbox4"/>android:id="@+id/submit"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="right"android:text="提交信息"/> packagenynu.edu.sy;importandroid.app.Activity;importandroid.os.Bundle;importandroid.view.Gravity;importandroid.view.View;importandroid.view.View.OnClickListener;importandroid.widget.CompoundButton;importandroid.widget.Button;importandroid.widget.CheckBox;importandroid.widget.RadioButton;importandroid.widget.RadioGroup;importandroid.widget.RadioGroup.OnCheckedChangeListener;importandroid.widget.TextView;importandroid.widget.Toast;publicclassTextViewSyActivityextendsActivity{/**Calledwhentheactivityisfirstcreated.*/privateTextViewtextview;privateButtonsubmit;privateCheckBoxcheckbox1,checkbox2,checkbox3,checkbox4;privateStrings=null; @OverridepublicvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.main);textview=(TextView)findViewById(R.id.textview);submit=(Button)findViewById(R.id.submit);submit.setOnClickListener(newOnClickbt());//取得每一个CheckBox对象checkbox1=(CheckBox)findViewById(R.id.checkbox1);checkbox2=(CheckBox)findViewById(R.id.checkbox2);checkbox3=(CheckBox)findViewById(R.id.checkbox3);checkbox4=(CheckBox)findViewById(R.id.checkbox4);//为每一个选项设置监听checkbox1.setOnCheckedChangeListener(newOnCheckchange());checkbox2.setOnCheckedChangeListener(newOnCheckchange());checkbox3.setOnCheckedChangeListener(newOnCheckchange());checkbox4.setOnCheckedChangeListener(newOnCheckchange());}privateclassOnCheckchangeimplementsCheckBox.OnCheckedChangeListener{publicvoidonCheckedChanged(CompoundButtonbuttonView,booleanisChecked){if(checkbox1.isChecked())s=s+checkbox1.getText()+"";elseif(checkbox2.isChecked())s=s+checkbox2.getText()+"";elseif(checkbox3.isChecked())s=s+checkbox3.getText()+"";elseif(checkbox4.isChecked())s=s+checkbox4.getText()+"";}}privateclassOnClickbtimplementsOnClickListener{publicvoidonClick(Viewv){DisplayToast(s);}}publicvoidDisplayToast(Stringstr){Toasttoast=Toast.makeText(this,str,Toast.LENGTH_SHORT);//设置Toast的显示位置toast.setGravity(Gravity.TOP,0,220);//显示Toasttoast.show();}}7.下拉列表框Spinner1)采用xml建立下拉列表数据,setOnItemSelectedListener进行监听。在values下建立intersts.xml,存放下拉列表的数据内容xmlversion="1.0"encoding="utf-8"?>篮球排球足球strings.xmlxmlversion="1.0"encoding="utf-8"?>HelloWorld,Activity01!xh_spinner_test您喜欢的球类运动是:main.xmlxmlversion="1.0"encoding="utf-8"?>android="android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent">android:text="@string/ys"android:id="@+id/TextView01"android:layout_width="fill_parent"android:layout_height="wrap_content"android:textSize="20sp"/>android:id="@+id/instersting"android:layout_width="fill_parent"android:layout_height="wrap_content"android:entries="@array/interestsdata"/>Java程序packagenynu.edu.sy;importandroid.app.Activity;importandroid.os.Bundle;importandroid.view.View;importandroid.widget.AdapterView;importandroid.widget.AdapterView.OnItemSelectedListener;importandroid.widget.ArrayAdapter;importandroid.widget.Spinner;importandroid.widget.TextView;importandroid.widget.Toast;publicclassUisyActivityextendsActivity{privateSpinnerinterestspinner=null;privateTextViewinfo=null;protectedvoidonCreate(BundlesavedInstanceState){//TODOAuto-generatedmethodstubsuper.onCreate(savedInstanceState);this.setContentView(R.layout.main);interestspinner=(Spinner)this.findViewById(R.id.instersting);info=(TextView)this.findViewById(R.id.TextView01);interestspinner.setOnItemSelectedListener(newnItemSelectedListenerImp());}privateclassnItemSelectedListenerImpimplementsOnItemSelectedListener{publicvoidonItemSelected(AdapterView>arg0,Viewarg1,intarg2,longarg3){//TODOAuto-generatedmethodstubStringvalues=arg0.getItemAtPosition(arg2).toString();Toast.makeText(UisyActivity.this,"您喜欢的球类运动是:"+values,1).show();}publicvoidonNothingSelected(AdapterView>arg0){//TODOAuto-generatedmethodstub}}}2)首先需要在布局中定时Spinner组件,然后将可选内容通过ArrayAdapter和下拉列表连接起来,最后要获得用户选择的选项,设计事件监听器setOnItemSelectedListener并实现onItemSelected,从而获得用户所选择的内容,最后通过setVisibility方法设置当前的显示项xmlversion="1.0"encoding="utf-8"?>android="android:orientation="vertical"android:layout_width="fill_parent"android:layout_heig
id="@+id/textview"
textSize="20sp"
/>
android:id="@+id/checkbox1"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="@string/checkbox1"/>android:id="@+id/checkbox2"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="@string/checkbox2"/>android:id="@+id/checkbox3"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="@string/checkbox3"/>android:id="@+id/checkbox4"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="@string/checkbox4"/>android:id="@+id/submit"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="right"android:text="提交信息"/> packagenynu.edu.sy;importandroid.app.Activity;importandroid.os.Bundle;importandroid.view.Gravity;importandroid.view.View;importandroid.view.View.OnClickListener;importandroid.widget.CompoundButton;importandroid.widget.Button;importandroid.widget.CheckBox;importandroid.widget.RadioButton;importandroid.widget.RadioGroup;importandroid.widget.RadioGroup.OnCheckedChangeListener;importandroid.widget.TextView;importandroid.widget.Toast;publicclassTextViewSyActivityextendsActivity{/**Calledwhentheactivityisfirstcreated.*/privateTextViewtextview;privateButtonsubmit;privateCheckBoxcheckbox1,checkbox2,checkbox3,checkbox4;privateStrings=null; @OverridepublicvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.main);textview=(TextView)findViewById(R.id.textview);submit=(Button)findViewById(R.id.submit);submit.setOnClickListener(newOnClickbt());//取得每一个CheckBox对象checkbox1=(CheckBox)findViewById(R.id.checkbox1);checkbox2=(CheckBox)findViewById(R.id.checkbox2);checkbox3=(CheckBox)findViewById(R.id.checkbox3);checkbox4=(CheckBox)findViewById(R.id.checkbox4);//为每一个选项设置监听checkbox1.setOnCheckedChangeListener(newOnCheckchange());checkbox2.setOnCheckedChangeListener(newOnCheckchange());checkbox3.setOnCheckedChangeListener(newOnCheckchange());checkbox4.setOnCheckedChangeListener(newOnCheckchange());}privateclassOnCheckchangeimplementsCheckBox.OnCheckedChangeListener{publicvoidonCheckedChanged(CompoundButtonbuttonView,booleanisChecked){if(checkbox1.isChecked())s=s+checkbox1.getText()+"";elseif(checkbox2.isChecked())s=s+checkbox2.getText()+"";elseif(checkbox3.isChecked())s=s+checkbox3.getText()+"";elseif(checkbox4.isChecked())s=s+checkbox4.getText()+"";}}privateclassOnClickbtimplementsOnClickListener{publicvoidonClick(Viewv){DisplayToast(s);}}publicvoidDisplayToast(Stringstr){Toasttoast=Toast.makeText(this,str,Toast.LENGTH_SHORT);//设置Toast的显示位置toast.setGravity(Gravity.TOP,0,220);//显示Toasttoast.show();}}7.下拉列表框Spinner1)采用xml建立下拉列表数据,setOnItemSelectedListener进行监听。在values下建立intersts.xml,存放下拉列表的数据内容xmlversion="1.0"encoding="utf-8"?>篮球排球足球strings.xmlxmlversion="1.0"encoding="utf-8"?>HelloWorld,Activity01!xh_spinner_test您喜欢的球类运动是:main.xmlxmlversion="1.0"encoding="utf-8"?>android="android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent">android:text="@string/ys"android:id="@+id/TextView01"android:layout_width="fill_parent"android:layout_height="wrap_content"android:textSize="20sp"/>android:id="@+id/instersting"android:layout_width="fill_parent"android:layout_height="wrap_content"android:entries="@array/interestsdata"/>Java程序packagenynu.edu.sy;importandroid.app.Activity;importandroid.os.Bundle;importandroid.view.View;importandroid.widget.AdapterView;importandroid.widget.AdapterView.OnItemSelectedListener;importandroid.widget.ArrayAdapter;importandroid.widget.Spinner;importandroid.widget.TextView;importandroid.widget.Toast;publicclassUisyActivityextendsActivity{privateSpinnerinterestspinner=null;privateTextViewinfo=null;protectedvoidonCreate(BundlesavedInstanceState){//TODOAuto-generatedmethodstubsuper.onCreate(savedInstanceState);this.setContentView(R.layout.main);interestspinner=(Spinner)this.findViewById(R.id.instersting);info=(TextView)this.findViewById(R.id.TextView01);interestspinner.setOnItemSelectedListener(newnItemSelectedListenerImp());}privateclassnItemSelectedListenerImpimplementsOnItemSelectedListener{publicvoidonItemSelected(AdapterView>arg0,Viewarg1,intarg2,longarg3){//TODOAuto-generatedmethodstubStringvalues=arg0.getItemAtPosition(arg2).toString();Toast.makeText(UisyActivity.this,"您喜欢的球类运动是:"+values,1).show();}publicvoidonNothingSelected(AdapterView>arg0){//TODOAuto-generatedmethodstub}}}2)首先需要在布局中定时Spinner组件,然后将可选内容通过ArrayAdapter和下拉列表连接起来,最后要获得用户选择的选项,设计事件监听器setOnItemSelectedListener并实现onItemSelected,从而获得用户所选择的内容,最后通过setVisibility方法设置当前的显示项xmlversion="1.0"encoding="utf-8"?>android="android:orientation="vertical"android:layout_width="fill_parent"android:layout_heig
id="@+id/checkbox1"
text="@string/checkbox1"
android:id="@+id/checkbox2"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="@string/checkbox2"/>android:id="@+id/checkbox3"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="@string/checkbox3"/>android:id="@+id/checkbox4"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="@string/checkbox4"/>android:id="@+id/submit"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="right"android:text="提交信息"/> packagenynu.edu.sy;importandroid.app.Activity;importandroid.os.Bundle;importandroid.view.Gravity;importandroid.view.View;importandroid.view.View.OnClickListener;importandroid.widget.CompoundButton;importandroid.widget.Button;importandroid.widget.CheckBox;importandroid.widget.RadioButton;importandroid.widget.RadioGroup;importandroid.widget.RadioGroup.OnCheckedChangeListener;importandroid.widget.TextView;importandroid.widget.Toast;publicclassTextViewSyActivityextendsActivity{/**Calledwhentheactivityisfirstcreated.*/privateTextViewtextview;privateButtonsubmit;privateCheckBoxcheckbox1,checkbox2,checkbox3,checkbox4;privateStrings=null; @OverridepublicvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.main);textview=(TextView)findViewById(R.id.textview);submit=(Button)findViewById(R.id.submit);submit.setOnClickListener(newOnClickbt());//取得每一个CheckBox对象checkbox1=(CheckBox)findViewById(R.id.checkbox1);checkbox2=(CheckBox)findViewById(R.id.checkbox2);checkbox3=(CheckBox)findViewById(R.id.checkbox3);checkbox4=(CheckBox)findViewById(R.id.checkbox4);//为每一个选项设置监听checkbox1.setOnCheckedChangeListener(newOnCheckchange());checkbox2.setOnCheckedChangeListener(newOnCheckchange());checkbox3.setOnCheckedChangeListener(newOnCheckchange());checkbox4.setOnCheckedChangeListener(newOnCheckchange());}privateclassOnCheckchangeimplementsCheckBox.OnCheckedChangeListener{publicvoidonCheckedChanged(CompoundButtonbuttonView,booleanisChecked){if(checkbox1.isChecked())s=s+checkbox1.getText()+"";elseif(checkbox2.isChecked())s=s+checkbox2.getText()+"";elseif(checkbox3.isChecked())s=s+checkbox3.getText()+"";elseif(checkbox4.isChecked())s=s+checkbox4.getText()+"";}}privateclassOnClickbtimplementsOnClickListener{publicvoidonClick(Viewv){DisplayToast(s);}}publicvoidDisplayToast(Stringstr){Toasttoast=Toast.makeText(this,str,Toast.LENGTH_SHORT);//设置Toast的显示位置toast.setGravity(Gravity.TOP,0,220);//显示Toasttoast.show();}}7.下拉列表框Spinner1)采用xml建立下拉列表数据,setOnItemSelectedListener进行监听。在values下建立intersts.xml,存放下拉列表的数据内容xmlversion="1.0"encoding="utf-8"?>篮球排球足球strings.xmlxmlversion="1.0"encoding="utf-8"?>HelloWorld,Activity01!xh_spinner_test您喜欢的球类运动是:main.xmlxmlversion="1.0"encoding="utf-8"?>android="android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent">android:text="@string/ys"android:id="@+id/TextView01"android:layout_width="fill_parent"android:layout_height="wrap_content"android:textSize="20sp"/>android:id="@+id/instersting"android:layout_width="fill_parent"android:layout_height="wrap_content"android:entries="@array/interestsdata"/>Java程序packagenynu.edu.sy;importandroid.app.Activity;importandroid.os.Bundle;importandroid.view.View;importandroid.widget.AdapterView;importandroid.widget.AdapterView.OnItemSelectedListener;importandroid.widget.ArrayAdapter;importandroid.widget.Spinner;importandroid.widget.TextView;importandroid.widget.Toast;publicclassUisyActivityextendsActivity{privateSpinnerinterestspinner=null;privateTextViewinfo=null;protectedvoidonCreate(BundlesavedInstanceState){//TODOAuto-generatedmethodstubsuper.onCreate(savedInstanceState);this.setContentView(R.layout.main);interestspinner=(Spinner)this.findViewById(R.id.instersting);info=(TextView)this.findViewById(R.id.TextView01);interestspinner.setOnItemSelectedListener(newnItemSelectedListenerImp());}privateclassnItemSelectedListenerImpimplementsOnItemSelectedListener{publicvoidonItemSelected(AdapterView>arg0,Viewarg1,intarg2,longarg3){//TODOAuto-generatedmethodstubStringvalues=arg0.getItemAtPosition(arg2).toString();Toast.makeText(UisyActivity.this,"您喜欢的球类运动是:"+values,1).show();}publicvoidonNothingSelected(AdapterView>arg0){//TODOAuto-generatedmethodstub}}}2)首先需要在布局中定时Spinner组件,然后将可选内容通过ArrayAdapter和下拉列表连接起来,最后要获得用户选择的选项,设计事件监听器setOnItemSelectedListener并实现onItemSelected,从而获得用户所选择的内容,最后通过setVisibility方法设置当前的显示项xmlversion="1.0"encoding="utf-8"?>android="android:orientation="vertical"android:layout_width="fill_parent"android:layout_heig
id="@+id/checkbox2"
text="@string/checkbox2"
android:id="@+id/checkbox3"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="@string/checkbox3"/>android:id="@+id/checkbox4"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="@string/checkbox4"/>android:id="@+id/submit"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="right"android:text="提交信息"/> packagenynu.edu.sy;importandroid.app.Activity;importandroid.os.Bundle;importandroid.view.Gravity;importandroid.view.View;importandroid.view.View.OnClickListener;importandroid.widget.CompoundButton;importandroid.widget.Button;importandroid.widget.CheckBox;importandroid.widget.RadioButton;importandroid.widget.RadioGroup;importandroid.widget.RadioGroup.OnCheckedChangeListener;importandroid.widget.TextView;importandroid.widget.Toast;publicclassTextViewSyActivityextendsActivity{/**Calledwhentheactivityisfirstcreated.*/privateTextViewtextview;privateButtonsubmit;privateCheckBoxcheckbox1,checkbox2,checkbox3,checkbox4;privateStrings=null; @OverridepublicvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.main);textview=(TextView)findViewById(R.id.textview);submit=(Button)findViewById(R.id.submit);submit.setOnClickListener(newOnClickbt());//取得每一个CheckBox对象checkbox1=(CheckBox)findViewById(R.id.checkbox1);checkbox2=(CheckBox)findViewById(R.id.checkbox2);checkbox3=(CheckBox)findViewById(R.id.checkbox3);checkbox4=(CheckBox)findViewById(R.id.checkbox4);//为每一个选项设置监听checkbox1.setOnCheckedChangeListener(newOnCheckchange());checkbox2.setOnCheckedChangeListener(newOnCheckchange());checkbox3.setOnCheckedChangeListener(newOnCheckchange());checkbox4.setOnCheckedChangeListener(newOnCheckchange());}privateclassOnCheckchangeimplementsCheckBox.OnCheckedChangeListener{publicvoidonCheckedChanged(CompoundButtonbuttonView,booleanisChecked){if(checkbox1.isChecked())s=s+checkbox1.getText()+"";elseif(checkbox2.isChecked())s=s+checkbox2.getText()+"";elseif(checkbox3.isChecked())s=s+checkbox3.getText()+"";elseif(checkbox4.isChecked())s=s+checkbox4.getText()+"";}}privateclassOnClickbtimplementsOnClickListener{publicvoidonClick(Viewv){DisplayToast(s);}}publicvoidDisplayToast(Stringstr){Toasttoast=Toast.makeText(this,str,Toast.LENGTH_SHORT);//设置Toast的显示位置toast.setGravity(Gravity.TOP,0,220);//显示Toasttoast.show();}}7.下拉列表框Spinner1)采用xml建立下拉列表数据,setOnItemSelectedListener进行监听。在values下建立intersts.xml,存放下拉列表的数据内容xmlversion="1.0"encoding="utf-8"?>篮球排球足球strings.xmlxmlversion="1.0"encoding="utf-8"?>HelloWorld,Activity01!xh_spinner_test您喜欢的球类运动是:main.xmlxmlversion="1.0"encoding="utf-8"?>android="android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent">android:text="@string/ys"android:id="@+id/TextView01"android:layout_width="fill_parent"android:layout_height="wrap_content"android:textSize="20sp"/>android:id="@+id/instersting"android:layout_width="fill_parent"android:layout_height="wrap_content"android:entries="@array/interestsdata"/>Java程序packagenynu.edu.sy;importandroid.app.Activity;importandroid.os.Bundle;importandroid.view.View;importandroid.widget.AdapterView;importandroid.widget.AdapterView.OnItemSelectedListener;importandroid.widget.ArrayAdapter;importandroid.widget.Spinner;importandroid.widget.TextView;importandroid.widget.Toast;publicclassUisyActivityextendsActivity{privateSpinnerinterestspinner=null;privateTextViewinfo=null;protectedvoidonCreate(BundlesavedInstanceState){//TODOAuto-generatedmethodstubsuper.onCreate(savedInstanceState);this.setContentView(R.layout.main);interestspinner=(Spinner)this.findViewById(R.id.instersting);info=(TextView)this.findViewById(R.id.TextView01);interestspinner.setOnItemSelectedListener(newnItemSelectedListenerImp());}privateclassnItemSelectedListenerImpimplementsOnItemSelectedListener{publicvoidonItemSelected(AdapterView>arg0,Viewarg1,intarg2,longarg3){//TODOAuto-generatedmethodstubStringvalues=arg0.getItemAtPosition(arg2).toString();Toast.makeText(UisyActivity.this,"您喜欢的球类运动是:"+values,1).show();}publicvoidonNothingSelected(AdapterView>arg0){//TODOAuto-generatedmethodstub}}}2)首先需要在布局中定时Spinner组件,然后将可选内容通过ArrayAdapter和下拉列表连接起来,最后要获得用户选择的选项,设计事件监听器setOnItemSelectedListener并实现onItemSelected,从而获得用户所选择的内容,最后通过setVisibility方法设置当前的显示项xmlversion="1.0"encoding="utf-8"?>android="android:orientation="vertical"android:layout_width="fill_parent"android:layout_heig
id="@+id/checkbox3"
text="@string/checkbox3"
android:id="@+id/checkbox4"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="@string/checkbox4"/>android:id="@+id/submit"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="right"android:text="提交信息"/> packagenynu.edu.sy;importandroid.app.Activity;importandroid.os.Bundle;importandroid.view.Gravity;importandroid.view.View;importandroid.view.View.OnClickListener;importandroid.widget.CompoundButton;importandroid.widget.Button;importandroid.widget.CheckBox;importandroid.widget.RadioButton;importandroid.widget.RadioGroup;importandroid.widget.RadioGroup.OnCheckedChangeListener;importandroid.widget.TextView;importandroid.widget.Toast;publicclassTextViewSyActivityextendsActivity{/**Calledwhentheactivityisfirstcreated.*/privateTextViewtextview;privateButtonsubmit;privateCheckBoxcheckbox1,checkbox2,checkbox3,checkbox4;privateStrings=null; @OverridepublicvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.main);textview=(TextView)findViewById(R.id.textview);submit=(Button)findViewById(R.id.submit);submit.setOnClickListener(newOnClickbt());//取得每一个CheckBox对象checkbox1=(CheckBox)findViewById(R.id.checkbox1);checkbox2=(CheckBox)findViewById(R.id.checkbox2);checkbox3=(CheckBox)findViewById(R.id.checkbox3);checkbox4=(CheckBox)findViewById(R.id.checkbox4);//为每一个选项设置监听checkbox1.setOnCheckedChangeListener(newOnCheckchange());checkbox2.setOnCheckedChangeListener(newOnCheckchange());checkbox3.setOnCheckedChangeListener(newOnCheckchange());checkbox4.setOnCheckedChangeListener(newOnCheckchange());}privateclassOnCheckchangeimplementsCheckBox.OnCheckedChangeListener{publicvoidonCheckedChanged(CompoundButtonbuttonView,booleanisChecked){if(checkbox1.isChecked())s=s+checkbox1.getText()+"";elseif(checkbox2.isChecked())s=s+checkbox2.getText()+"";elseif(checkbox3.isChecked())s=s+checkbox3.getText()+"";elseif(checkbox4.isChecked())s=s+checkbox4.getText()+"";}}privateclassOnClickbtimplementsOnClickListener{publicvoidonClick(Viewv){DisplayToast(s);}}publicvoidDisplayToast(Stringstr){Toasttoast=Toast.makeText(this,str,Toast.LENGTH_SHORT);//设置Toast的显示位置toast.setGravity(Gravity.TOP,0,220);//显示Toasttoast.show();}}7.下拉列表框Spinner1)采用xml建立下拉列表数据,setOnItemSelectedListener进行监听。在values下建立intersts.xml,存放下拉列表的数据内容xmlversion="1.0"encoding="utf-8"?>篮球排球足球strings.xmlxmlversion="1.0"encoding="utf-8"?>HelloWorld,Activity01!xh_spinner_test您喜欢的球类运动是:main.xmlxmlversion="1.0"encoding="utf-8"?>android="android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent">android:text="@string/ys"android:id="@+id/TextView01"android:layout_width="fill_parent"android:layout_height="wrap_content"android:textSize="20sp"/>android:id="@+id/instersting"android:layout_width="fill_parent"android:layout_height="wrap_content"android:entries="@array/interestsdata"/>Java程序packagenynu.edu.sy;importandroid.app.Activity;importandroid.os.Bundle;importandroid.view.View;importandroid.widget.AdapterView;importandroid.widget.AdapterView.OnItemSelectedListener;importandroid.widget.ArrayAdapter;importandroid.widget.Spinner;importandroid.widget.TextView;importandroid.widget.Toast;publicclassUisyActivityextendsActivity{privateSpinnerinterestspinner=null;privateTextViewinfo=null;protectedvoidonCreate(BundlesavedInstanceState){//TODOAuto-generatedmethodstubsuper.onCreate(savedInstanceState);this.setContentView(R.layout.main);interestspinner=(Spinner)this.findViewById(R.id.instersting);info=(TextView)this.findViewById(R.id.TextView01);interestspinner.setOnItemSelectedListener(newnItemSelectedListenerImp());}privateclassnItemSelectedListenerImpimplementsOnItemSelectedListener{publicvoidonItemSelected(AdapterView>arg0,Viewarg1,intarg2,longarg3){//TODOAuto-generatedmethodstubStringvalues=arg0.getItemAtPosition(arg2).toString();Toast.makeText(UisyActivity.this,"您喜欢的球类运动是:"+values,1).show();}publicvoidonNothingSelected(AdapterView>arg0){//TODOAuto-generatedmethodstub}}}2)首先需要在布局中定时Spinner组件,然后将可选内容通过ArrayAdapter和下拉列表连接起来,最后要获得用户选择的选项,设计事件监听器setOnItemSelectedListener并实现onItemSelected,从而获得用户所选择的内容,最后通过setVisibility方法设置当前的显示项xmlversion="1.0"encoding="utf-8"?>android="android:orientation="vertical"android:layout_width="fill_parent"android:layout_heig
id="@+id/checkbox4"
text="@string/checkbox4"
android:id="@+id/submit"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="right"android:text="提交信息"/> packagenynu.edu.sy;importandroid.app.Activity;importandroid.os.Bundle;importandroid.view.Gravity;importandroid.view.View;importandroid.view.View.OnClickListener;importandroid.widget.CompoundButton;importandroid.widget.Button;importandroid.widget.CheckBox;importandroid.widget.RadioButton;importandroid.widget.RadioGroup;importandroid.widget.RadioGroup.OnCheckedChangeListener;importandroid.widget.TextView;importandroid.widget.Toast;publicclassTextViewSyActivityextendsActivity{/**Calledwhentheactivityisfirstcreated.*/privateTextViewtextview;privateButtonsubmit;privateCheckBoxcheckbox1,checkbox2,checkbox3,checkbox4;privateStrings=null; @OverridepublicvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.main);textview=(TextView)findViewById(R.id.textview);submit=(Button)findViewById(R.id.submit);submit.setOnClickListener(newOnClickbt());//取得每一个CheckBox对象checkbox1=(CheckBox)findViewById(R.id.checkbox1);checkbox2=(CheckBox)findViewById(R.id.checkbox2);checkbox3=(CheckBox)findViewById(R.id.checkbox3);checkbox4=(CheckBox)findViewById(R.id.checkbox4);//为每一个选项设置监听checkbox1.setOnCheckedChangeListener(newOnCheckchange());checkbox2.setOnCheckedChangeListener(newOnCheckchange());checkbox3.setOnCheckedChangeListener(newOnCheckchange());checkbox4.setOnCheckedChangeListener(newOnCheckchange());}privateclassOnCheckchangeimplementsCheckBox.OnCheckedChangeListener{publicvoidonCheckedChanged(CompoundButtonbuttonView,booleanisChecked){if(checkbox1.isChecked())s=s+checkbox1.getText()+"";elseif(checkbox2.isChecked())s=s+checkbox2.getText()+"";elseif(checkbox3.isChecked())s=s+checkbox3.getText()+"";elseif(checkbox4.isChecked())s=s+checkbox4.getText()+"";}}privateclassOnClickbtimplementsOnClickListener{publicvoidonClick(Viewv){DisplayToast(s);}}publicvoidDisplayToast(Stringstr){Toasttoast=Toast.makeText(this,str,Toast.LENGTH_SHORT);//设置Toast的显示位置toast.setGravity(Gravity.TOP,0,220);//显示Toasttoast.show();}}7.下拉列表框Spinner1)采用xml建立下拉列表数据,setOnItemSelectedListener进行监听。在values下建立intersts.xml,存放下拉列表的数据内容xmlversion="1.0"encoding="utf-8"?>篮球排球足球strings.xmlxmlversion="1.0"encoding="utf-8"?>HelloWorld,Activity01!xh_spinner_test您喜欢的球类运动是:main.xmlxmlversion="1.0"encoding="utf-8"?>android="android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent">android:text="@string/ys"android:id="@+id/TextView01"android:layout_width="fill_parent"android:layout_height="wrap_content"android:textSize="20sp"/>android:id="@+id/instersting"android:layout_width="fill_parent"android:layout_height="wrap_content"android:entries="@array/interestsdata"/>Java程序packagenynu.edu.sy;importandroid.app.Activity;importandroid.os.Bundle;importandroid.view.View;importandroid.widget.AdapterView;importandroid.widget.AdapterView.OnItemSelectedListener;importandroid.widget.ArrayAdapter;importandroid.widget.Spinner;importandroid.widget.TextView;importandroid.widget.Toast;publicclassUisyActivityextendsActivity{privateSpinnerinterestspinner=null;privateTextViewinfo=null;protectedvoidonCreate(BundlesavedInstanceState){//TODOAuto-generatedmethodstubsuper.onCreate(savedInstanceState);this.setContentView(R.layout.main);interestspinner=(Spinner)this.findViewById(R.id.instersting);info=(TextView)this.findViewById(R.id.TextView01);interestspinner.setOnItemSelectedListener(newnItemSelectedListenerImp());}privateclassnItemSelectedListenerImpimplementsOnItemSelectedListener{publicvoidonItemSelected(AdapterView>arg0,Viewarg1,intarg2,longarg3){//TODOAuto-generatedmethodstubStringvalues=arg0.getItemAtPosition(arg2).toString();Toast.makeText(UisyActivity.this,"您喜欢的球类运动是:"+values,1).show();}publicvoidonNothingSelected(AdapterView>arg0){//TODOAuto-generatedmethodstub}}}2)首先需要在布局中定时Spinner组件,然后将可选内容通过ArrayAdapter和下拉列表连接起来,最后要获得用户选择的选项,设计事件监听器setOnItemSelectedListener并实现onItemSelected,从而获得用户所选择的内容,最后通过setVisibility方法设置当前的显示项xmlversion="1.0"encoding="utf-8"?>android="android:orientation="vertical"android:layout_width="fill_parent"android:layout_heig
id="@+id/submit"
layout_gravity="right"
text="提交信息"
importandroid.view.View;
importandroid.view.View.OnClickListener;
importandroid.widget.CompoundButton;
importandroid.widget.Button;
importandroid.widget.CheckBox;
importandroid.widget.RadioGroup.OnCheckedChangeListener;
publicclassTextViewSyActivityextendsActivity{
/**Calledwhentheactivityisfirstcreated.*/
privateTextViewtextview;
privateButtonsubmit;
privateCheckBoxcheckbox1,checkbox2,checkbox3,checkbox4;
privateStrings=null;
@Override
textview=(TextView)findViewById(R.id.textview);
submit=(Button)findViewById(R.id.submit);
submit.setOnClickListener(newOnClickbt());
//取得每一个CheckBox对象
checkbox1=(CheckBox)findViewById(R.id.checkbox1);
checkbox2=(CheckBox)findViewById(R.id.checkbox2);
checkbox3=(CheckBox)findViewById(R.id.checkbox3);
checkbox4=(CheckBox)findViewById(R.id.checkbox4);
//为每一个选项设置监听
checkbox1.setOnCheckedChangeListener(newOnCheckchange());
checkbox2.setOnCheckedChangeListener(newOnCheckchange());
checkbox3.setOnCheckedChangeListener(newOnCheckchange());
checkbox4.setOnCheckedChangeListener(newOnCheckchange());
privateclassOnCheckchangeimplementsCheckBox.OnCheckedChangeListener{
publicvoidonCheckedChanged(CompoundButtonbuttonView,
booleanisChecked){
if(checkbox1.isChecked())
s=s+checkbox1.getText()+"";
elseif(checkbox2.isChecked())
s=s+checkbox2.getText()+"";
elseif(checkbox3.isChecked())
s=s+checkbox3.getText()+"";
elseif(checkbox4.isChecked())
s=s+checkbox4.getText()+"";
privateclassOnClickbtimplementsOnClickListener{
publicvoidonClick(Viewv){
DisplayToast(s);
Toasttoast=Toast.makeText(this,str,Toast.LENGTH_SHORT);
//设置Toast的显示位置
//显示Toast
7.下拉列表框Spinner
1)采用xml建立下拉列表数据,setOnItemSelectedListener进行监听。
在values下建立intersts.xml,存放下拉列表的数据内容
篮球
排球
足球
strings.xml
HelloWorld,Activity01!
xh_spinner_test
您喜欢的球类运动是:
main.xml
android="android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent">android:text="@string/ys"android:id="@+id/TextView01"android:layout_width="fill_parent"android:layout_height="wrap_content"android:textSize="20sp"/>android:id="@+id/instersting"android:layout_width="fill_parent"android:layout_height="wrap_content"android:entries="@array/interestsdata"/>Java程序packagenynu.edu.sy;importandroid.app.Activity;importandroid.os.Bundle;importandroid.view.View;importandroid.widget.AdapterView;importandroid.widget.AdapterView.OnItemSelectedListener;importandroid.widget.ArrayAdapter;importandroid.widget.Spinner;importandroid.widget.TextView;importandroid.widget.Toast;publicclassUisyActivityextendsActivity{privateSpinnerinterestspinner=null;privateTextViewinfo=null;protectedvoidonCreate(BundlesavedInstanceState){//TODOAuto-generatedmethodstubsuper.onCreate(savedInstanceState);this.setContentView(R.layout.main);interestspinner=(Spinner)this.findViewById(R.id.instersting);info=(TextView)this.findViewById(R.id.TextView01);interestspinner.setOnItemSelectedListener(newnItemSelectedListenerImp());}privateclassnItemSelectedListenerImpimplementsOnItemSelectedListener{publicvoidonItemSelected(AdapterView>arg0,Viewarg1,intarg2,longarg3){//TODOAuto-generatedmethodstubStringvalues=arg0.getItemAtPosition(arg2).toString();Toast.makeText(UisyActivity.this,"您喜欢的球类运动是:"+values,1).show();}publicvoidonNothingSelected(AdapterView>arg0){//TODOAuto-generatedmethodstub}}}2)首先需要在布局中定时Spinner组件,然后将可选内容通过ArrayAdapter和下拉列表连接起来,最后要获得用户选择的选项,设计事件监听器setOnItemSelectedListener并实现onItemSelected,从而获得用户所选择的内容,最后通过setVisibility方法设置当前的显示项xmlversion="1.0"encoding="utf-8"?>android="android:orientation="vertical"android:layout_width="fill_parent"android:layout_heig
android:text="@string/ys"android:id="@+id/TextView01"android:layout_width="fill_parent"android:layout_height="wrap_content"android:textSize="20sp"/>android:id="@+id/instersting"android:layout_width="fill_parent"android:layout_height="wrap_content"android:entries="@array/interestsdata"/>Java程序packagenynu.edu.sy;importandroid.app.Activity;importandroid.os.Bundle;importandroid.view.View;importandroid.widget.AdapterView;importandroid.widget.AdapterView.OnItemSelectedListener;importandroid.widget.ArrayAdapter;importandroid.widget.Spinner;importandroid.widget.TextView;importandroid.widget.Toast;publicclassUisyActivityextendsActivity{privateSpinnerinterestspinner=null;privateTextViewinfo=null;protectedvoidonCreate(BundlesavedInstanceState){//TODOAuto-generatedmethodstubsuper.onCreate(savedInstanceState);this.setContentView(R.layout.main);interestspinner=(Spinner)this.findViewById(R.id.instersting);info=(TextView)this.findViewById(R.id.TextView01);interestspinner.setOnItemSelectedListener(newnItemSelectedListenerImp());}privateclassnItemSelectedListenerImpimplementsOnItemSelectedListener{publicvoidonItemSelected(AdapterView>arg0,Viewarg1,intarg2,longarg3){//TODOAuto-generatedmethodstubStringvalues=arg0.getItemAtPosition(arg2).toString();Toast.makeText(UisyActivity.this,"您喜欢的球类运动是:"+values,1).show();}publicvoidonNothingSelected(AdapterView>arg0){//TODOAuto-generatedmethodstub}}}2)首先需要在布局中定时Spinner组件,然后将可选内容通过ArrayAdapter和下拉列表连接起来,最后要获得用户选择的选项,设计事件监听器setOnItemSelectedListener并实现onItemSelected,从而获得用户所选择的内容,最后通过setVisibility方法设置当前的显示项xmlversion="1.0"encoding="utf-8"?>android="android:orientation="vertical"android:layout_width="fill_parent"android:layout_heig
text="@string/ys"
id="@+id/TextView01"
android:id="@+id/instersting"android:layout_width="fill_parent"android:layout_height="wrap_content"android:entries="@array/interestsdata"/>Java程序packagenynu.edu.sy;importandroid.app.Activity;importandroid.os.Bundle;importandroid.view.View;importandroid.widget.AdapterView;importandroid.widget.AdapterView.OnItemSelectedListener;importandroid.widget.ArrayAdapter;importandroid.widget.Spinner;importandroid.widget.TextView;importandroid.widget.Toast;publicclassUisyActivityextendsActivity{privateSpinnerinterestspinner=null;privateTextViewinfo=null;protectedvoidonCreate(BundlesavedInstanceState){//TODOAuto-generatedmethodstubsuper.onCreate(savedInstanceState);this.setContentView(R.layout.main);interestspinner=(Spinner)this.findViewById(R.id.instersting);info=(TextView)this.findViewById(R.id.TextView01);interestspinner.setOnItemSelectedListener(newnItemSelectedListenerImp());}privateclassnItemSelectedListenerImpimplementsOnItemSelectedListener{publicvoidonItemSelected(AdapterView>arg0,Viewarg1,intarg2,longarg3){//TODOAuto-generatedmethodstubStringvalues=arg0.getItemAtPosition(arg2).toString();Toast.makeText(UisyActivity.this,"您喜欢的球类运动是:"+values,1).show();}publicvoidonNothingSelected(AdapterView>arg0){//TODOAuto-generatedmethodstub}}}2)首先需要在布局中定时Spinner组件,然后将可选内容通过ArrayAdapter和下拉列表连接起来,最后要获得用户选择的选项,设计事件监听器setOnItemSelectedListener并实现onItemSelected,从而获得用户所选择的内容,最后通过setVisibility方法设置当前的显示项xmlversion="1.0"encoding="utf-8"?>android="android:orientation="vertical"android:layout_width="fill_parent"android:layout_heig
id="@+id/instersting"
entries="@array/interestsdata"
Java程序
importandroid.widget.AdapterView;
importandroid.widget.AdapterView.OnItemSelectedListener;
importandroid.widget.ArrayAdapter;
importandroid.widget.Spinner;
privateSpinnerinterestspinner=null;
privateTextViewinfo=null;
protectedvoidonCreate(BundlesavedInstanceState){
//TODOAuto-generatedmethodstub
this.setContentView(R.layout.main);
interestspinner=(Spinner)this.findViewById(R.id.instersting);
info=(TextView)this.findViewById(R.id.TextView01);
interestspinner.setOnItemSelectedListener(newnItemSelectedListenerImp());
privateclassnItemSelectedListenerImpimplementsOnItemSelectedListener{
publicvoidonItemSelected(AdapterView
>arg0,Viewarg1,intarg2,
longarg3){
Stringvalues=arg0.getItemAtPosition(arg2).toString();
Toast.makeText(UisyActivity.this,"您喜欢的球类运动是:
"+values,1).show();
publicvoidonNothingSelected(AdapterView
>arg0){
2)首先需要在布局中定时Spinner组件,然后将可选内容通过ArrayAdapter和下拉列表连接起来,最后要获得用户选择的选项,设计事件监听器setOnItemSelectedListener并实现onItemSelected,从而获得用户所选择的内容,最后通过setVisibility方法设置当前的显示项
android="android:orientation="vertical"android:layout_width="fill_parent"android:layout_heig
layout_heig
copyright@ 2008-2023 冰点文库 网站版权所有
经营许可证编号:鄂ICP备19020893号-2