【问题标题】:way to put a text view in side a listview将文本视图放在列表视图中的方法
【发布时间】:2014-01-21 15:11:58
【问题描述】:

我有一个显示城市、州、邮政编码等地址信息的列表视图。我想随着状态的变化添加一个文本视图标题。

那么,有没有办法在列表视图内的数据之间放置一个文本视图。 enter link description here

【问题讨论】:

    标签: android android-layout android-listview textview


    【解决方案1】:

    BaseAdapter 有两个函数处理不同类型的行:

    getItemViewType(int position)getViewTypeCount()

    您可以按如下方式实现这些来做您正在寻找的事情:

    //Define constants for your different view types
    public final int CONTACT_INFO_TYPE = 1;
    public final int HEADER_TYPE = 2;
    
    //Return which view type should be shown, based on the position in the list view
    @Override
    public int getItemViewType(int position) {
        if(something) {
            return HEADER_TYPE;
        } else {
            return CONTACT
    }
    
    //Return the count of different views shown in the list
    @Override
    public int getViewTypeCount() {
        return 2;
    }
    
    //Use getItemViewType(...) to decide what kind of View you should return
    @Override
    public View getView (int position, View convertView, ViewGroup parent) {
        int type = getItemViewType(position);
        if(type == CONTACT_INFO_TYPE) {
            //Return a view containing contact info
        } else {
            //Return a view containing header info
        }
    }
    

    【讨论】:

      【解决方案2】:

      您可能希望在ListView 中使用两种不同的视图类型。这个post 可能会有所帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多