tags:

views:

30

answers:

1

I am working in an android application that uses a list view. I currently have a XML for the row layout with only one text view. Based on certain conditions, some rows will have one additional button and some other rows may have 2 additional buttons. Can I override the getView method of the adapter class to do this logic? is there any performance issue?

+1  A: 

Have a row layout with 2 buttons, then:

public View getView(int position, View convertView, ViewGroup parent){
    // the usual convertView stuff
    if(convertView == null){
        convertView = layoutInflater.inflate(//TODO);
        Tag tag = new Tag();
        convertView.setTag(tag);
        tag.button1 = (Button)convertView.findViewById(R.id.btn1);
        tag.button2 = (Button)convertView.findViewById(R.id.btn2);
    }
    Tag tag = (Tag)convertView.getTag();
    boolean buttonOneShown = //TODO;
    boolean buttonTwoShown = //TODO;
    tag.button1.setVisibility(buttonOneShown ? VISIBLE : GONE);
    tag.button1.setVisibility(buttonTwoShown ? VISIBLE : GONE);
}

Performance would be just fine.

alex
How is the Tag object defined? I can't seem to find it in the Android API documantation...
droid_fan