My question revolves around reminder Spinner
's. I am trying to allow the user to add at maximum, 5 reminders. But I also don't want to show all five. These reminders are each Spinner
's which have multiple choices. When the user clicks to add a reminder, it will do so. When they want to take one away, they can do that as well, and when they want to add another one, the new one appears at the bottom. Any idea of how to go about this?
My original implementation was to have 5 already defined (4 "gone"), but then if the user wants to add one, it becomes "visible". Problem with that is that if you take away a reminder from the view by making it "gone", and add it back, it does not apear at the bottom, but rather back where it originally was (unless it was already the last spinner). Now I am lost as to how to dynamically add spinners specifically under certain views. Any ideas would be much appreciated!
Edit: what I have so far/ 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