If you think the Android project ListViewAnimations listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/*
* Copyright 2014 Niek Haarman/*www.java2s.com*/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/package com.haarman.listviewanimations;
import android.content.Context;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.nhaarman.listviewanimations.ArrayAdapter;
import com.nhaarman.listviewanimations.itemmanipulation.swipedismiss.undo.UndoAdapter;
import se.emilsjolander.stickylistheaders.StickyListHeadersAdapter;
publicclass MyListAdapter extends ArrayAdapter<String> implements UndoAdapter, StickyListHeadersAdapter {
privatefinal Context mContext;
public MyListAdapter(final Context context) {
mContext = context;
for (int i = 0; i < 1000; i++) {
add(mContext.getString(R.string.row_number, i));
}
}
@Override
publiclong getItemId(finalint position) {
return getItem(position).hashCode();
}
@Override
publicboolean hasStableIds() {
return true;
}
@Override
public View getView(finalint position, final View convertView, final ViewGroup parent) {
TextView view = (TextView) convertView;
if (view == null) {
view = (TextView) LayoutInflater.from(mContext).inflate(R.layout.list_row, parent, false);
}
view.setText(getItem(position));
return view;
}
@NonNull
@Override
public View getUndoView(finalint position, final View convertView, @NonNull final ViewGroup parent) {
View view = convertView;
if (view == null) {
view = LayoutInflater.from(mContext).inflate(R.layout.undo_row, parent, false);
}
return view;
}
@NonNull
@Override
public View getUndoClickView(@NonNull final View view) {
return view.findViewById(R.id.undo_row_undobutton);
}
@Override
public View getHeaderView(finalint position, final View convertView, final ViewGroup parent) {
TextView view = (TextView) convertView;
if (view == null) {
view = (TextView) LayoutInflater.from(mContext).inflate(R.layout.list_header, parent, false);
}
view.setText(mContext.getString(R.string.header, getHeaderId(position)));
return view;
}
@Override
publiclong getHeaderId(finalint position) {
return position / 10;
}
}