Android Open Source - AndroidTouchEditableListView Editable Array Adapter






From Project

Back to project page AndroidTouchEditableListView.

License

The source code is released under:

Copyright (c) 2014 Serge Desmedt Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Soft...

If you think the Android project AndroidTouchEditableListView 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

package be.trojkasoftware.android.toucheditablelistview;
//  w  w  w. j  ava  2 s.  co m
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public abstract class EditableArrayAdapter<T> 
extends ArrayAdapter<T> 
implements TouchEditableListView.InsertViewFactory, TouchEditableListView.OnInsertListener,
  TouchEditableListView.DeleteViewFactory, TouchEditableListView.OnDeleteListener {

  public EditableArrayAdapter(Context context, int resource) {
    super(context, resource);
    
    mResource = resource;
  }
  
  public EditableArrayAdapter(Context context, int resource, int textViewResourceId) {
    super(context, resource, textViewResourceId);
    
    mResource = resource;
    mTextViewResourceId = textViewResourceId;
  }
  
  public EditableArrayAdapter(Context context, int resource, T[] objects) {
    super(context, resource, objects);
    
    mResource = resource;
  }
  
  public EditableArrayAdapter(Context context, int resource, int textViewResourceId, T[] objects) {
    super(context, resource, textViewResourceId, objects);
    
    mResource = resource;
    mTextViewResourceId = textViewResourceId;
  }
  
  public EditableArrayAdapter(Context context, int resource, List<T> objects) {
    super(context, resource, objects);
    
    mResource = resource;
  }
  
  public EditableArrayAdapter(Context context, int resource, int textViewResourceId, List<T> objects) {
    super(context, resource, textViewResourceId, objects);
    
    mObjects = objects;
    
    mResource = resource;
    mTextViewResourceId = textViewResourceId;
  }
  
  @Override
  public View getInsertView(int afterPosition, int beforePosition) {
    
    LayoutInflater inflater = LayoutInflater.from(super.getContext());
    View v = inflater.inflate(mResource, null);
    
    TextView txtView = (TextView)v.findViewById(mTextViewResourceId);
    
    Object o = getNewObject(afterPosition, beforePosition);
    txtView.setText(o.toString());
    
    return v;
  }
  
  @Override
  public void insert(int afterPosition, int beforePosition) {
    if (afterPosition == -1 || beforePosition == 0) {
      super.insert(getNewObject(afterPosition, beforePosition), 0);  
    }
    else if (afterPosition == (mObjects.size() - 1) || beforePosition == -1) {
      super.insert(getNewObject(afterPosition, beforePosition), mObjects.size());            
    }
    else {
      super.insert(getNewObject(afterPosition, beforePosition), afterPosition + 1);            
    }
  }
  
  @Override
  public View getDeleteView(int position) {
    
    LayoutInflater inflater = LayoutInflater.from(super.getContext());
    View v = inflater.inflate(R.layout.delete_action_layout, null);
    
    return v;
  }
  
  @Override
  public void delete(int position) {
    super.remove(super.getItem(position));
  }
  
  public abstract T getNewObject(int afterPosition, int beforePosition);
  
  protected List<T> mObjects;
  
  protected int mResource;
  protected int mTextViewResourceId;

}




Java Source Code List

be.trojkasoftware.android.obsolete.TouchEditableDividerDrawable.java
be.trojkasoftware.android.obsolete.TouchEditableInsertManager.java
be.trojkasoftware.android.obsolete.TouchEditableListView10.java
be.trojkasoftware.android.obsolete.TouchEditableListView20.java
be.trojkasoftware.android.obsolete.TouchEditableListView2.java
be.trojkasoftware.android.sample.AndroidTouchEditableListViewSampleActivity.java
be.trojkasoftware.android.sample.CustomEditableArrayAdapter.java
be.trojkasoftware.android.touch.TouchDataStore.java
be.trojkasoftware.android.touch.TouchData.java
be.trojkasoftware.android.toucheditablelistview.EditableArrayAdapter.java
be.trojkasoftware.android.toucheditablelistview.TouchEditableActionView.java
be.trojkasoftware.android.toucheditablelistview.TouchEditableItemView.java
be.trojkasoftware.android.toucheditablelistview.TouchEditableListView.java
be.trojkasoftware.android.toucheditablelistview.TouchEditableStateManager.java