0

我是初学者。我已经尝试了很多,但我不知道我该怎么做:

我有一个ArrayAdapter。这显示了所有项目,if position == 3它还应该显示一个标签。

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    LayoutInflater inflater = (LayoutInflater) context
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    View rowView;
    if (position == 3){
        rowView = inflater.inflate(R.layout.event_date, parent, false);

        // set text of label ...

        // now I want to display also the normal item
    } else {
        rowView = inflater.inflate(R.layout.events_list, parent, false);

        // set text of item ...

    }

    return rowView;
}

它显示标签,但我不知道如果它显示标签,我怎么能显示正常项目。我怎样才能做到这一点?

4

1 回答 1

1

尝试使用一个新的布局,它同时包含event_dateevents_lists

像这样的东西:

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    LayoutInflater inflater = (LayoutInflater) context
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    View rowView;
    if (position == 3){
        rowView = inflater.inflate(R.layout.event_date_plus_events_list, parent, false);

        // set text of label ...


    } else {
        rowView = inflater.inflate(R.layout.events_list, parent, false);

    }

        // set text of item ...

    return rowView;
}
于 2013-07-05T17:12:43.897 回答