A week ago I asked a question on stackoverflow about having a listview with different kinds of items in it.
I know how to populate a list with custom items via custom adapter. But how do I populate it with a few different types of items?
At the time I didnt know that it would have made a difference so I mentioned I only have 4 types of list items not to complicate things. I got some responses with extremely simple cases explained (2 types of items with a single view inside each one). I dont think I can implement those approaches explained in the examples I got, I need a more object oriented approach.
I would like to have a separate class that takes an XML layout and deals with its views and its buttons.
Something like this:
public class MyProfileCommentAdapter extends BaseAdapter { private ArrayListI need to have about 20 of these and put them all in a list view (the activity feed of my app), depending on what activities have recently occurred in my app. Each different activity has a separate XML defined with as much view elements in it, as this one, all doing and displaying different stuff.
Now, If I was to use the suggested approach,
@Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder = null; int type = getItemViewType(position); Log.v(LOG_TAG, "getView " + position + " " + convertView + " type = " + type); if (convertView == null) { holder = new ViewHolder(); switch (type) { case TYPE_ITEM: convertView = mInflater.inflate(R.layout.item, null); holder.textView = (TextView)convertView.findViewById(R.id.text); break; case TYPE_SEPARATOR: convertView = mInflater.inflate(R.layout.separator, null); holder.textView = (TextView)convertView.findViewById(R.id.textSeparator); break; default: break; } convertView.setTag(holder); } else { holder = (ViewHolder)convertView.getTag(); } holder.textView.setText(mData.get(position)); return convertView; }Looks simple, doesnt it? But in my case, I should have 20 different cases in the SWITCH and each one should have 20-30 rows of code in it. I dont want to implement it this way. Sadly, I have no clue of what to do...