To inflate different layouts for strings, you need to override getViewItemType and getViewTypeCount .
You should watch the video in the link.
http://www.youtube.com/watch?v=wDBM6wVEO70
private static final int TYPE_ITEM1 = 0; private static final int TYPE_ITEM2 = 1; private static final int TYPE_ITEM3 = 2;
Then
int type; @Override public int getItemViewType(int position) { if (position== 0){ type = TYPE_ITEM1; } else if (position == 1){ type = TYPE_ITEM2; } else { type= TYPE_ITEM3 ; } return type; } @Override public int getViewTypeCount() { return 3; } @Override public View getView(int position, View convertView, ViewGroup parent) { View row = convertView; LayoutInflater inflater = null; int type = getItemViewType(position); // instead of if else you can use a case if (convertView == null) { if (type == TYPE_ITEM1 { //infalte layout of type1 convertView = mInflater.inflate(R.layout.layouttype1, parent, false); } if (type == TYPE_ITEM2) { //infalte layout of type2 convertView = mInflater.inflate(R.layout.layouttype2, parent, false); } else { //infalte layout of normaltype convertView = mInflater.inflate(R.layout.layouttype3, parent, false); } ...// rest of the code return convertView; }
source share