I have an adapter for a list of heterogeneous items, all of Action
type.
ActionAdapter.java
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
public class ActionAdapter extends ArrayAdapter<Action> {
Context context;
int layoutResourceId;
ArrayList<Action> actions = null;
public ActionAdapter(Context context, int layoutResourceId, ArrayList<Action> actions) {
super(context, layoutResourceId, actions);
this.layoutResourceId = layoutResourceId;
this.context = context;
this.actions = actions;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
ActionHolder holder = null;
if(row == null)
{
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
row = inflater.inflate(actions.get(position).getViewId(), parent, false);
holder = new ActionHolder();
holder.title = (TextView)row.findViewById(R.id.action_title);
row.setTag(holder);
}
else
{
holder = (ActionHolder)row.getTag();
}
Action action = actions.get(position);
holder.title.setText(action.getTitle());
return row;
}
static class ActionHolder
{
TextView title;
}
}
Action is an abstract class, so with actions.get(position).getViewId()
I get the appropriate layout for that action, EVERYONE with DIFFERENT fields (textviews, edittexts and so on).
I have the user dynamically add/remove actions, and I want the list mantained on screen rotation etc. I found that I can add android:configChanges="orientation|screenSize"
in manifest, but documentation says that it should be the last resort.
What is the best approach to this? I mean, should I keep that tag in manifest or it's better, ie., to bind list in a db? In the latter case, how can I handle with actions having different fields?
And, what is the more robust way to save lists permanently? For example I'd like the user could save such action list as a template for future uses
If you think I can do something in a better way (for example extending BaseAdapter instead of ArrayAdapter), explaining why, I'm open-minded to changes