我必须显示一个微调器,它在运行时从适配器获取其内容。当微调器出现在屏幕上时选择一个值应该出现在它上面而不是适配器中的第一个值。请帮助
答案 0 :(得分:1)
如果您想要选择集合中的特定项目,请查看: Spinner.setSelection(int position)
答案 1 :(得分: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);
<?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"/>
答案 2 :(得分:0)
**试试吧...... **
2.ArrayAdapter Purchesedadapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item,_Purchesedlistarray); Purchesedadapter .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
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
}
});