6

MergeAdapter、StickyListHeaders、および ListViewAnimations Android ライブラリに参加した人はいますか?

私のニーズは次のとおりです。

  • 1 つの垂直スクロール ビュー内の複数の ListView
  • 異種アイテム ビュー
  • ヘッダーで区切られた複数のリスト項目。固定する必要があります
  • 一部のリスト項目を展開する機能
  • それらのいくつかをドラッグアンドドロップします
  • アンドロイド14+をサポート

私のエキストラ:

  • CursorAdapters に依存する

チェリーピック:

  • 時々、一番上のヘッダー (リストの一部ではなく別のビューであり、そのままにしておくことをお勧めします) を少し上にスライドさせる必要があります。私の結合されたリストは従う必要がありますが、同時に、常に底に取り付けられるように、その高さをアニメーションで拡張します。

言及されたライブラリは次のとおりです。

可能であれば希望と、落とし穴を避けるための役立つヒントを教えてください。たぶん、他のライブラリを使用する必要があります。または、自分でそれを書く必要があります:(

====編集====

最終的に、やりたかったことのスタブを作成することができました (2014 年初頭)。これは機能的で拡張可能でドラッグ可能なリストビューとアダプター ライブラリで、アニメーションが優れています (スティッキー ヘッダーはまだありません)。レポは次のとおりです。

RecyclerView が利用可能になったので、過度に複雑なリストビュー コードを使用する必要はありません。ここにクイックスイッチガイドがあります - http://andraskindler.com/2014/11/22/migrating-to-recyclerview/

4

2 に答える 2

1

最終的に、ヘッダーを処理するアダプターを作成しました。

アダプタ クラスの使用:

StickyHeaderMergeAdapter stickyHeaderMergeAdapter = new StickyHeaderMergeAdapter(this.getActivity(), R.layout.list_item_header, R.id.text1);
stickyHeaderMergeAdapter.addAdapter(
                myTypcalAdapter,
                R.string.stringName
);
this.stickyHeaderListView.setAdapter(stickyHeaderMergeAdapter);

アダプタ クラス:

package mypackagename.widget;

import android.content.Context;
import android.support.annotation.IdRes;
import android.support.annotation.LayoutRes;
import android.support.annotation.StringRes;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListAdapter;
import android.widget.TextView;

import com.commonsware.cwac.merge.MergeAdapter;
import org.apache.commons.lang3.NotImplementedException;
import java.util.LinkedHashMap;

import se.emilsjolander.stickylistheaders.StickyListHeadersAdapter;

public class StickyHeaderMergeAdapter extends MergeAdapter implements StickyListHeadersAdapter {
    private final LinkedHashMap<ListAdapter,Integer> adapterViewHashMap = new LinkedHashMap<>();
    private final Context context;
    private final int headerLayoutId;
    private final int headerLayoutTextId;

    public StickyHeaderMergeAdapter(Context context, @LayoutRes int headerLayoutId, @IdRes int headerLayoutTextId) {
        this.context = context;
        this.headerLayoutId = headerLayoutId;
        this.headerLayoutTextId = headerLayoutTextId;
    }

    public void addAdapter(ListAdapter listAdapter, @StringRes int stringId) {
        super.addAdapter(listAdapter);
        this.adapterViewHashMap.put(listAdapter, stringId);
    }

    @Override
    public void addAdapter(ListAdapter adapter) {
        throw new NotImplementedException("You should use addAdapter(ListAdapter, View)");
    }

    @Override
    public View getHeaderView(int position, View convertView, ViewGroup parent) {
        if (convertView == null)
            convertView = View.inflate(this.context, this.headerLayoutId, null);

        ((TextView) convertView.findViewById(this.headerLayoutTextId)).setText(
                this.adapterViewHashMap.get(this.getAdapter(position))
        );

        return convertView;
    }

    @Override
    public long getHeaderId(int i) {
        ListAdapter listAdapter = this.getAdapter(i);
        if (!this.adapterViewHashMap.containsKey(listAdapter))
            return 0;

        return this.adapterViewHashMap.get(listAdapter);
    }
}
于 2014-09-29T19:57:24.540 に答える