importandroid.app.Activity;
importandroid.os.Bundle;
importandroid.widget.ArrayAdapter;
importandroid.widget.Spinner;
importcom.sec.android.touchwiz.samples.R;
/**
*@authoryh0409.kim
*spinnersampleExample
*
*<usedfileList>
*spinnersample1xml_main:Mainform.(TextView+Spinner)
*spinnersample1xml_item:textviewinthespinneritem
*spinnersample1xml_dropdown_item:checkboxintthespinneritem(CheckedTextView)
*/
publicclassSpinnerSample1XmlextendsActivity{
SpinnermS1;
SpinnermS2;
ArrayAdapter<CharSequence>mAdapter;
@Override
publicvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.spinnersample1xml_main);
mS1=(Spinner)findViewById(R.id.spinner1);
/**
*createFromResource(Contextcontext,inttextArrayResId,inttextViewResId)
*textArrayResId:selectedtextvalueinthespinner.
*textViewResId:definedtextviewlayout,控制没下拉时【选中项】的显示
*/
mAdapter=ArrayAdapter.createFromResource(
this,R.array.type1,R.layout.spinnersample1xml_item);
/**
*setDropDownViewResource(intresource)
*设置下拉项的显示
*/
mAdapter.setDropDownViewResource(R.layout.spinnersample1xml_dropdown_item);
mS1.setAdapter(mAdapter);
mS2=(Spinner)findViewById(R.id.spinner2);
mAdapter=ArrayAdapter.createFromResource(this,R.array.type2,
R.layout.spinnersample1xml_item);
mAdapter.setDropDownViewResource(R.layout.spinnersample1xml_dropdown_item);
mS2.setAdapter(mAdapter);
}
}
文件1:spinnersample1xml_dropdown_item.xml
<?xmlversion="1.0"encoding="utf-8"?>
<CheckedTextView
xmlns:android="http://schemas.android.com/apk/res/android<wbr style="line-height:25px">"<br style="line-height:25px"> android:id="@android:id/text1"<br style="line-height:25px"> style="?android:attr/spinnerDropDownItemStyle"<br style="line-height:25px"> android:singleLine="true"<br style="line-height:25px"> android:layout_width="fill_parent"<br style="line-height:25px"> android:layout_height="?android:attr/listPreferredItemHeight"<br style="line-height:25px"> android:ellipsize="marquee"/><br style="line-height:25px"><span style="line-height:25px">文件2</span>:spinnersample1xml_item.xml<br style="line-height:25px"> <?xmlversion="1.0"encoding="utf-8"?><br style="line-height:25px"> <TextViewxmlns:android="<a target="_blank" rel="nofollow" href="http://schemas.android.com/apk/res/android" style="color:rgb(207,121,28); line-height:25px; text-decoration:none">http://schemas.android.com/apk/res/android</a><wbr style="line-height:25px">"<br style="line-height:25px"> android:id="@android:id/text1"<br style="line-height:25px"> style="?android:attr/spinnerItemStyle"<br style="line-height:25px"> android:singleLine="true"<br style="line-height:25px"> android:layout_width="fill_parent"<br style="line-height:25px"> android:layout_height="wrap_content"<br style="line-height:25px"> android:ellipsize="marquee"/></wbr></wbr>
importandroid.os.Bundle;
importandroid.widget.ArrayAdapter;
importandroid.widget.Spinner;
importcom.sec.android.touchwiz.samples.R;
/**
*@authoryh0409.kim
*spinnersampleExample
*
*<usedfileList>
*spinnersample1xml_main:Mainform.(TextView+Spinner)
*spinnersample1xml_item:textviewinthespinneritem
*spinnersample1xml_dropdown_item:checkboxintthespinneritem(CheckedTextView)
*/
publicclassSpinnerSample1XmlextendsActivity{
SpinnermS1;
SpinnermS2;
ArrayAdapter<CharSequence>mAdapter;
@Override
publicvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.spinnersample1xml_main);
mS1=(Spinner)findViewById(R.id.spinner1);
/**
*createFromResource(Contextcontext,inttextArrayResId,inttextViewResId)
*textArrayResId:selectedtextvalueinthespinner.
*textViewResId:definedtextviewlayout,控制没下拉时【选中项】的显示
*/
mAdapter=ArrayAdapter.createFromResource(
this,R.array.type1,R.layout.spinnersample1xml_item);
/**
*setDropDownViewResource(intresource)
*设置下拉项的显示
*/
mAdapter.setDropDownViewResource(R.layout.spinnersample1xml_dropdown_item);
mS1.setAdapter(mAdapter);
mS2=(Spinner)findViewById(R.id.spinner2);
mAdapter=ArrayAdapter.createFromResource(this,R.array.type2,
R.layout.spinnersample1xml_item);
mAdapter.setDropDownViewResource(R.layout.spinnersample1xml_dropdown_item);
mS2.setAdapter(mAdapter);
}
}
文件1:spinnersample1xml_dropdown_item.xml
<?xmlversion="1.0"encoding="utf-8"?>
<CheckedTextView
xmlns:android="http://schemas.android.com/apk/res/android<wbr style="line-height:25px">"<br style="line-height:25px"> android:id="@android:id/text1"<br style="line-height:25px"> style="?android:attr/spinnerDropDownItemStyle"<br style="line-height:25px"> android:singleLine="true"<br style="line-height:25px"> android:layout_width="fill_parent"<br style="line-height:25px"> android:layout_height="?android:attr/listPreferredItemHeight"<br style="line-height:25px"> android:ellipsize="marquee"/><br style="line-height:25px"><span style="line-height:25px">文件2</span>:spinnersample1xml_item.xml<br style="line-height:25px"> <?xmlversion="1.0"encoding="utf-8"?><br style="line-height:25px"> <TextViewxmlns:android="<a target="_blank" rel="nofollow" href="http://schemas.android.com/apk/res/android" style="color:rgb(207,121,28); line-height:25px; text-decoration:none">http://schemas.android.com/apk/res/android</a><wbr style="line-height:25px">"<br style="line-height:25px"> android:id="@android:id/text1"<br style="line-height:25px"> style="?android:attr/spinnerItemStyle"<br style="line-height:25px"> android:singleLine="true"<br style="line-height:25px"> android:layout_width="fill_parent"<br style="line-height:25px"> android:layout_height="wrap_content"<br style="line-height:25px"> android:ellipsize="marquee"/></wbr></wbr>