添加在运行时键可在各行中的列表视图 [英] Adding buttons at run time to each row in a list view

查看:94
本文介绍了添加在运行时键可在各行中的列表视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用列表视图Android应用程序的工作。我现在有是只有一个文本视图的行布局的XML。在一定条件下,某些行将具有一个附加键和其他一些行可以具有2个额外的按钮。我可以覆盖适配器类的getView方法来完成这个逻辑?是否有任何性能问题?

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?

推荐答案

有一排布局与2个按钮,则:

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);
}

表现会就好了。

这篇关于添加在运行时键可在各行中的列表视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆