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 a开发者_JS百科dapter class to do this logic? is there any performance issue?
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.
精彩评论