Remove and Undo Listview Item with slide

Screen Shot 


Source Code 

Activity Code :

package com.example.undo;

import java.util.ArrayList;

import android.app.ListActivity;
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 {

       @Override
       protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              getListView().setDivider(null);
       }

       protected ArrayAdapter<String> createListAdapter() {
              return new MyListAdapter(thisgetItems());
       }

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

       private static class MyListAdapter extends ArrayAdapter<String> {

              private Context mContext;

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

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

              @Override
              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;
              }
       }
}

Comments

Popular posts from this blog

Android Objective type Question and Answers

Android Questions and Answers for written exams