private Spinner mSpnrCustomer;
private List<String> mCustomerList = new ArrayList<String>();
mCustomerList= Arrays.asList(getResources().getStringArray(R.array.customer_names));
mSpnrCustomer.setAdapter(new SpinnerRoomTypeAdapter(context,mCustomerList));
这里使用ArrayList中的相应数据成功填充Spinner。我想添加一个额外的字符串,而不是底部的ArrayList中的字符串,例如“CreateUser
”。在选择这个时我需要它来打开一个弹出窗口。我怎么能这样做?
答案 0 :(得分:0)
您需要 notify 适配器有关列表中的更改
mCustomerList = new ArrayList<String>();
//populate the list
mCustomerList =
Arrays.asList(getResources().getStringArray(R.array.customer_names));
//set the adapter
mSpnrCustomer.setAdapter(new SpinnerRoomTypeAdapter(context,mCustomerList));
//add something to the List
mCustomerList.add("Foo");
//notify the adapter
myAdapter.notifyDataSetChanged();
现在您遇到的问题是您将适配器设置为匿名实例...那么您将需要一个变量
答案 1 :(得分:0)
简单:
private Spinner mSpnrCustomer;
private List<String> mCustomerList = new ArrayList<String>();
mCustomerList= Arrays.asList(getResources().getStringArray(R.array.customer_names));
String createUser= "CreateUser";
mCustomerList.add(createUser);
mSpnrCustomer.setAdapter(new SpinnerRoomTypeAdapter(context,mCustomerList));
说明:您有一个包含String对象的ArrayList。如果你想为它添加新的字符串,你可以使用ArrayList方法添加它。
答案 2 :(得分:0)
试试这个
List<String> list = new LinkedList<>(Arrays.asList(getResources().getStringArray(R.array.customer_name)));
list.add("CreateUser");
mSpnrCustomer.setAdapter(new SpinnerRoomTypeAdapter(context,list));
答案 3 :(得分:0)
private Spinner mSpnrCustomer;
private List<String> mCustomerList = new ArrayList<String>();
customer_names.add("Value");
mCustomerList= Arrays.asList(getResources().getStringArray(R.array.customer_names));
mSpnrCustomer.setAdapter(new SpinnerRoomTypeAdapter(context,mCustomerList));
在调用微调器之前添加一行代码 customer_names.add(&#34; Value&#34;);