您可以使用 ListPopupWindow 为 TextView 创建自定义微调器,这意味着当单击 TextView 时,ListPopupWindow 会像微调器下拉列表一样打开,您可以选择一个元素。如果你需要,我会帮助你。
ListPopupWindow numberList;
TextView spDays;
ArrayList<Map<String, String>>() listTrans;
in oncreate() spDays.setonclicklistner(this);spDays.setText("Select");
setNumberListSpinnerView();
in onclick(){
when spDays clicked :- numberList.show();
}
void setNumberListSpinnerView() {
numberList= new ListPopupWindow(this);
numberList.setAnchorView(spDays);
numberList.setOnItemClickListener((new AdapterView.OnItemClickListener() {
@Override
getListItem();
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Map map = listTrans.get(position);
spDays.setText(map.get("circle_name").toString());
circle_name = map.get("circle_name") + "";
circle_id = map.get("circle_id").toString();
circleList.dismiss();
Log.d("Circle id:", circle_id + "");
getRetails();
}
}));
}
void getListItem(){
String[] numbers = {"1","2","3","4","5","6"};
listTrans = new ArrayList<Map<String, String>>();
LinkedHashMap<String, String> tran = new LinkedHashMap<String, String>();
for (String number : numbers) {
tran.put("numbers", number);
listTrans.add(tran);
}
SimpleAdapter adapter = new SimpleAdapter(AddRetailSurvey.this, listTrans,
android.R.layout.simple_spinner_dropdown_item,
new String[]{"numbers"},
new int[]{android.R.id.text1});
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
numberList.setAdapter(adapter);
}
检查此代码并根据您的要求进行修改。如果您发现任何问题,我会在这里为您提供帮助。:)