0

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 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.