我必须显示一个微调器,它在运行时从适配器获取其内容。当微调器出现在屏幕上时选择一个值应该出现在它上面而不是适配器中的第一个值。请帮助
问问题
803 次
3 回答
1
如果您希望选择集合中的特定项目,请查看: Spinner.setSelection(int position)
于 2012-08-06T11:49:29.187 回答
0
然后,您必须在字符串数组的第一个位置添加该文本。
Spinner rangeSpinner = (Spinner)findViewById(R.id.rangeSpinner);
String[] items = new String[] {"Select Product","Bread","Milk"};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.layout.custom_spinner_textview_layout, items);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
rangeSpinner.setAdapter(adapter);
custom_spinner_textview_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/spinnerTarget"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="18.0sp"
android:textColor="@color/grey_text"
android:gravity="left"/>
于 2012-08-06T11:54:18.720 回答
0
**星期五试试吧……**
1.String[] _Purchesedlistarray = { "必需", "已购买" };
2.ArrayAdapter Purchesedadapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, _Purchesedlistarray); Purchesedadapter .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
_PurchesedSpinner.setAdapter(Purchesedadapter);
3._PurchesedSpinner .setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent,
View view, int position, long id) {
// TODO Auto-generated method stub
Appsconstent._Purchesed = parent.getItemAtPosition(
position).toString();
System.out.println("the Value is--------------->"
+ Appsconstent._Purchesed);
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
}
});
于 2014-07-02T05:20:36.027 回答