有没有人加入MergeAdapter,StickyListHeaders和ListViewAnimations安卓库?
我的需求是:
我的演员:
Cherrypick:
提到的图书馆是:
如果有可能,请给我一些希望,以及如何避免陷阱的一些有用的提示。也许我应该使用其他一些库。或者我只需要自己写一下:(
==== EDITED ====
最后,我设法建立了我希望做的事情(2014年初)。它是功能可扩展和可拖动的listview和适配器库,具有漂亮的动画(还没有粘性标头)。回复:
由于RecyclerView现已推出,因此无需使用过于复杂的列表视图代码。这是快速切换指南 - http://andraskindler.com/2014/11/22/migrating-to-recyclerview/。
答案 0 :(得分:1)
来自ListViewAnimations wiki: http://nhaarman.github.io/ListViewAnimations/#getting-started
ListViewAnimations还支持外观动画 StickyListHeaderListViews。您必须将AnimationAdapter包装在一个 StickyListHeadersAdapterDecorator:
StickyListHeadersListView listView = (...); AlphaInAnimationAdapter
animationAdapter = new AlphaInAnimationAdapter(adapter);
StickyListHeadersAdapterDecorator stickyListHeadersAdapterDecorator =
new StickyListHeadersAdapterDecorator(animationAdapter);
stickyListHeadersAdapterDecorator.setStickyListHeadersListView(listView);
listView.setAdapter(stickyListHeadersAdapterDecorator);
就像普通的ListView一样,你可以使用任何实现 AnimationAdapter类。
结合StickyListHeaders and MergeAdapter的解决方案,uber-mergeadapter应该是可能的:P
答案 1 :(得分: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);
Adapter类:
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);
}
}