9
This post is related to this ViewHolder not working. On that post, I was following a tutorial on how to use ViewHolder on a ListView. What I want now is to have the last item on a ListView to have a different layout than the rest. Here's my code:
int lastpos = mList.size()-1;
System.out.println("position: "+position+" mlist: "+lastpos);
if(position==lastpos){
view = vi.inflate(R.layout.list_item_record, null);
holder.textView = (TextView)view.findViewById(R.id.record_view);
}else{
view = vi.inflate(R.layout.list_item_bn, null);
holder.textView = (TextView)view.findViewById(R.id.tv_name);
}
view.setTag(holder);
I just get the ListView size minus 1 and have a condition that checks the if current position is equal to the last item. However, this code sets the last item's layout same as the rest. getView method full code:
private class CustomListAdapter extends ArrayAdapter {
private ArrayList mList;
private Context mContext;
public CustomListAdapter(Context context, int textViewResourceId,
ArrayList list) {
super(context, textViewResourceId, list);
this.mList = list;
this.mContext = context;
}
public View getView(final int position, View convertView, ViewGroup parent) {
View view = convertView;
final ToggleButton tb;
if (view == null) {
ViewHolder holder = new ViewHolder();
LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
int lastpos = mList.size()-1;
System.out.println("position: "+position+" mlist: "+lastpos);
if(position==lastpos){
view = vi.inflate(R.layout.list_item_