我是Android的新手,我试图设计一个微调器下拉窗口小部件,用户选择的值未在下拉框中设置为选定值[不显示在下图中的标记区域]。 / p>
我的设计xml:
<Spinner
android:id="@+id/propertyid"
android:layout_width="fill_parent"
android:layout_marginTop="160dip"
android:padding="230dp"
android:layout_height="60dp"
android:background="@android:drawable/btn_dropdown"
android:prompt="@string/prompt"
android:spinnerMode="dropdown" />
Java代码:
private Spinner spin;
List<String> list = new ArrayList<String>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_user);
list.add("list 1");
list.add("list 2");
list.add("list 3");
imgPreview = (ImageView) findViewById(R.id.imgPreview);
spin = (Spinner) findViewById(R.id.propertyid);
spin.setOnItemSelectedListener(this);
ArrayAdapter<String> aa = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, list);
aa.setDropDownViewResource(
android.R.layout.simple_spinner_dropdown_item);
spin.setAdapter(aa);
spin.setSelection(0);
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position,
long id) {
// TODO Auto-generated method stub
spin.setSelection(position);
String item = list.get(position);
System.out.println("&&&&&&----&&&&&&"+position+item);
// Showing selected spinner item
Toast.makeText(parent.getContext(), "Selected: " + item, Toast.LENGTH_LONG).show();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
}
请有人帮助我显示选择列表值
答案 0 :(得分:1)
只需删除
即可android:padding="230dp"
它正在将您的物品移出界限, 所有其余的代码都很好。