我在listview的标题处创建了一个微调器。如何在其中添加文字?我想在spinnerText中显示文本。
String[] spinnerText = { "Sort by date posted (latest to oldest)", "Sort by price (lowest to highest)"};
LayoutInflater inflater = LayoutInflater.from(this);
View spinTop = inflater.inflate(R.layout.spin, null);
getListView().addHeaderView(spinTop);
答案 0 :(得分:1)
你应该尝试使用像这样的ArrayAdapter:
spinTop.setAdapter(new ArrayAdapter<String>(context, android.R.layout.simple_spinner_item, spinnerText));
答案 1 :(得分:0)
您必须使用ArrayAdapter<String>
,如下所示:
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,spinnerText);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinTop.setAdapter(adapter);
此外,您还必须投射spinTop
:
Spinner spinTop = (Spinner) inflater.inflate(R.layout.spin, null);