views:

32

answers:

1

I want to add a different type of item (like a simple textview) to the last position in my ListView.

I extends the SimpleAdapter and override some methods:

@Override
public int getCount() {
    if (super.getCount() == 0) {
        return 0;
    } else {
        return super.getCount() + 1;
    }
}

@Override
public Object getItem(int position) {
    if (position == getCount() - 1) {
        return null;
    } else {
        return super.getItem(position);
    }
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View v;
    if (position == getCount() - 1) {
        if (convertView == null) {
            v = new TextView(mContext);
        } else {
            v = convertView;
        }

        return v;
    } else {
        return super.getView(position, convertView, parent);
    }
}

But it did not work. What is the problem or how to add one? Thanks.

+1  A: 

Try using a footer instead, in your activity try

getListView().addFooter(View.inflate(R.layout.my_footer, null));

You have to do this before you add the adapter to the listview.

schwiz
working great! thanks!
shiami
my code: getListView().addFooterView(View.inflate(this, R.layout.footer, null));
shiami
ahh yes I forgot it wants a parent arguments. Thanks
schwiz