Thursday, September 12, 2013

Remove and Undo Listview Item with slide in Android

Remove and Undo Listview Item with slide in Android

This post about how to Undo removed item from listview like Gmail.
Screen Shot 

Source Code 

Activity Code :

package com.example.undo;

import java.util.ArrayList;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class MyListActivity extends ListActivity {

       protected void onCreate(Bundle savedInstanceState) {

       protected ArrayAdapter<String> createListAdapter() {
              return new MyListAdapter(this, getItems());

       public static ArrayList<String> getItems() {
              ArrayList<String> items = new ArrayList<String>();
              for (int i = 0; i < 1000; i++) {
              return items;

       private static class MyListAdapter extends ArrayAdapter<String> {

              private Context mContext;

              public MyListAdapter(Context context, ArrayList<String> items) {
                     mContext = context;

              public long getItemId(int position) {
                     return getItem(position).hashCode();

              public View getView(int position, View convertView, ViewGroup parent) {
                     TextView tv = (TextView) convertView;
                     if (tv == null) {
                           tv = (TextView) LayoutInflater.from(mContext).inflate(R.layout.list_row, parent, false);
                     tv.setText("This is row number " + getItem(position));
                     return tv;



Check out this may be help you

Related Posts Plugin for WordPress, Blogger...