Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Dirk Bruere at NeoPax Newsgroups: comp.lang.java.programmer Subject: Re: ArrayAdapter Date: Thu, 31 Mar 2011 12:21:55 +0100 Organization: Dirk Bruere at Neopax Lines: 68 Message-ID: <8vj6efFla6U1@mid.individual.net> References: <8vi26oFvh2U1@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 VC9xZfSupn/+EGmbfWlheQ2Xn+LJAuS3ufnzdGxeUQMRINcvq+ Cancel-Lock: sha1:F62dyY3bSViMqvtkCRCNaaRC+9I= 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:2643 On 31/03/2011 11:19, Andreas Leitgeb wrote: > Arved Sandstrom wrote: >> On 11-03-30 10:03 PM, Dirk Bruere at NeoPax wrote: >>> I have an ArrayAdapter in main. >>> How do I access it from another class? >> I trust you mean a Main class, not a "main" method. > > Now, that you spell it out like this, it seems more likely, that > an ArrayAdapter-instance is stored in a local variable of public > static void main(String[] args). > > Unless main passes the reference to another class, I doubt > there'd be a way for that other class to access the reference. > > Perhaps, reflection can still do it, but I wouldn't bet on it. > Back online again. Here is a code sample: public class controller extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Context currentContext = this; final BlinkAPI blinkAPI = new BlinkAPI(currentContext); lvVideo = (ListView)findViewById(R.id.ListViewVideo); radioTitleAdapter = new ArrayAdapter(this,android.R.layout.simple_expandable_list_item_1,BlinkAPI.videoArrayList); lvVideo.setAdapter(radioTitleAdapter); } ... } //******************************************* public class BlinkAPI { private static Context mContext; static ListView albumsLV, videoLV, tracksLV, artistsLV, radioLV; public BlinkAPI( Context ctx) { BlinkAPI.mContext = ctx; radioLV = (ListView )((Activity) mContext).findViewById(R.id.ListViewRadio); } private static void updateRadioTitles( ) { ... radioTitleAdapter.add(titleStr); //PROBLEM radioTitleAdapter.notifyDataSetChanged(); //PROBLEM } How do I get at radioTitleAdapter? -- Dirk http://www.neopax.com/technomage/ - My new book - Magick and Technology