我的问题围绕着提醒Spinner
。我试图允许用户最多添加 5 个提醒。但我也不想展示所有五个。这些提醒每个Spinner
都有多个选择。当用户点击添加提醒时,它会这样做。当他们想拿走一个时,他们也可以这样做,当他们想添加另一个时,新的会出现在底部。知道如何去做吗?
我最初的实现是已经定义了 5 个(4 个“消失”),但是如果用户想要添加一个,它就会变成“可见的”。问题在于,如果您通过使其“消失”从视图中删除提醒并将其添加回来,它不会出现在底部,而是回到原来的位置(除非它已经是最后一个微调器) . 现在我不知道如何在某些视图下专门动态添加微调器。任何想法将不胜感激!
编辑:我到目前为止/ RemindersAdapter.java
public class RemindersAdapter extends BaseAdapter{
ArrayList<Spinner> shownReminders;
public RemindersAdapter(Context c) {
shownReminders.add(new Spinner(c));
shownReminders.add(new Spinner(c));
shownReminders.add(new Spinner(c));
shownReminders.add(new Spinner(c));
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return shownReminders.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return shownReminders.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View view, ViewGroup parent) {
if(view == null) {
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
view = inflater.inflate(R.layout.reminder_spinner, parent, false);
}
Log.d("TAG", "This is trying to run");
Spinner reminderSpinner = (Spinner)view.findViewById(R.id.duplicate_reminder);
reminderSpinner.setTag("1"); //this tag will be used to check which it is and correctly put the reminder into its respective String
ArrayAdapter<CharSequence> reminderAdapter = ArrayAdapter.createFromResource(
parent.getContext(), R.array.reminders_array, android.R.layout.simple_spinner_item);
reminderAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
reminderSpinner.setAdapter(reminderAdapter);
reminderSpinner.setOnItemSelectedListener(new MyOnReminderSelectedListener());
shownReminders.add(position, reminderSpinner);
return view;
}
/*
* Listener for when the reminder spinner gets a value the user entered
* */
public class MyOnReminderSelectedListener implements OnItemSelectedListener{
@Override
public void onItemSelected(AdapterView<?> parent, View view, int pos,
long id) {
//does nothing for now
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// Do nothing for now
}
}//end of MyOnReminderSelectedListener innerclass