2

I created a listview that has a custom SimpleCursorAdapter. I want to place a header in the first element in the list. 8 views fit on the screen at a time. When I scroll down to the ninth view, the header of the 1st element appears. At least I believe that is what is happening. I removed a button above the listview allowing all of the elements to appear on screen and only the first element had the header.

I believe I am forcing a new view to be inflated each time. I have read up a bit on convertview and it appears to be something that you have to implement manually.

@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {

    final LayoutInflater inflater = LayoutInflater.from(context);
    int position = cursor.getPosition();
    View v;
    v = inflater.inflate(R.layout.roster_lv_row_entry_with_header, parent, false);      
    if(position > 0)
        v = inflater.inflate(R.layout.roster_lv_row_entry_no_header, parent, false);

    return v;
4

1 に答える 1

4

(final int position, View convertView, ViewGroup parent)アダプター クラスでメソッドをオーバーライドする必要があります。

  1. convertViewパラメータに新しい値を割り当てます (必要に応じて、ただし、適切なタイプである場合はそれを使用し、に基づいて適切なデータを入力することをお勧めします。yourListData.get(position)ここyourListDataで、List<?>拡張子など)。
  2. それからそれを返します。
于 2011-04-17T06:55:23.247 に答える