0

I have a arrayList= new ArrayList<FriendsData>(); that is define inside an interface in my Base Activity.

public interface RequestUsers
    {
        ArrayList<FriendsData> arrayList    =  new ArrayList<FriendsData>();

    }

I already tried cleaning and restarting eclipse but nothing happens.

Please expain why -1 I will remove my question if you think I am stupid as compared to people here at STACKOVERFLOW.

Mihir
  • 2,064
  • 2
  • 21
  • 28

1 Answers1

2

A variable in an interface can only be a constant (i.e. static final). Even so, it is oft considered poor style to have fields in interfaces.

An alternative is to have an abstract class as opposed to the interface if you genuinely need it in the superclass as opposed to individual extending instances.

Quetzalcoatl
  • 3,037
  • 2
  • 18
  • 27
  • My class already have a `BaseFragment Class`. I want use the arraylist both inside my fragment and model class. – Mihir Jun 12 '13 at 11:03
  • Then surely composition would be more appropriate? Perhaps supplying each of the classes with the same `ArrayList` that you want them to share as a parameter in the constructor would be a nicer design? – Quetzalcoatl Jun 12 '13 at 11:05
  • The second class is an adapter class that is initialized only once . It is based on arraylist items that are generated at the runtime. Adapter has a listner that cause events according to arraylist. – Mihir Jun 12 '13 at 11:10
  • Ok, so why can't you pass the same ArrayList to the other class that needs it in some shape or form, be it a parametrized constructor, mutators, etc? – Quetzalcoatl Jun 12 '13 at 11:17
  • here is the exact scenario. I have a `gridview` which has a layout inflated in it that contains a `imageview` and a `checkbox`. The `gridview` is initialized via separate adapter class. There are two listners for this `gridview` one is a `checkbox` that is inside the adapter class and other is the `gridview OnItemClickListener` and they both are accessing the same `arraylist`. – Mihir Jun 12 '13 at 11:25
  • I can also make two more listners inside `adpater` and `fragment class` that can give me 'arraylist' changed event but that will ber cumbersome. – Mihir Jun 12 '13 at 11:28