Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!news.musoftware.de!wum.musoftware.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Dirk Bruere at NeoPax Newsgroups: comp.lang.java.programmer Subject: Re: Initializing from context passing Date: Sat, 23 Apr 2011 20:34:56 +0100 Organization: Dirk Bruere at Neopax Lines: 56 Message-ID: <91gnv8F6ooU1@mid.individual.net> References: <91ga4tF38vU1@mid.individual.net> Reply-To: dirk.bruere@gmail.com Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net 9Gwv0957vded7yJU6fQ0ugny+32Xwr4QGd4tNl6nW3RY3Esgnn Cancel-Lock: sha1:Yzkp72gu3GYQO4E0Hdpgd0BMero= User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.15) Gecko/20110303 Thunderbird/3.1.9 In-Reply-To: Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:3221 On 23/04/2011 17:35, Daniele Futtorovic wrote: > On 23/04/2011 17:39, Dirk Bruere at NeoPax allegedly wrote: >> I have a Data class of the form: >> >> Data >> ( >> public static ListView albumsLV; >> public static ArrayAdapter albumsTitleAdapter >> public static ArrayList albumsTitleArrayList = new >> ArrayList(); >> >> Data(Context ctx) >> { >> albumsLV = (ListView )((Activity) ctx).findViewById(R.id.ListViewAlbums); >> >> albumsTitleAdapter = new ArrayAdapter(ctx, >> android.R.layout.simple_expandable_list_item_1,albumsTitleArrayList); >> } >> >> } >> >> and in the main method{ >> >> public void onCreate(Bundle savedInstanceState) >> { >> super.onCreate(savedInstanceState); >> setContentView(R.layout.main); >> Context currentContext = this; >> >> Data data = new Data(currentContext); >> >> } >> >> lvAlbum = (ListView)findViewById(R.id.ListViewAlbums); >> lvAlbum.setAdapter(Data.albumsTitleAdapter); >> } >> >> I never use Data data variable again. >> Is that sufficient to initialize the static parameters in Data class? >> > > Yeah, but it's crap. At least make it a static method e.g. > Data.init(Context). > > And do use interface types rather than implementations, unless you > specifically rely on a detail of the implementation (which is often a > bad sign). That is, make it a List, not an ArrayList. I would appreciate a pointer to an example. Everything I have come across in the Android examples I have seen uses ArrayAdapter -- Dirk http://www.neopax.com/technomage/ - My new book - Magick and Technology