Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > ArrayAdapter

Reply
Thread Tools

ArrayAdapter

 
 
Dirk Bruere at NeoPax
Guest
Posts: n/a
 
      03-31-2011
I have an ArrayAdapter in main.
How do I access it from another class?

--
Dirk

http://www.neopax.com/technomage/ - My new book - Magick and Technology
 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      03-31-2011
On Thu, 31 Mar 2011 02:03:24 +0100, Dirk Bruere at NeoPax
<(E-Mail Removed)> wrote, quoted or indirectly quoted someone who
said :

>I have an ArrayAdapter in main.
>How do I access it from another class?


You would have to show some code. I have never heard of an
ArrayAdapter.
--
Roedy Green Canadian Mind Products
http://mindprod.com
There are only two industries that refer to their customers as "users".
~ Edward Tufte

 
Reply With Quote
 
 
 
 
Lawrence D'Oliveiro
Guest
Posts: n/a
 
      03-31-2011
In message <(E-Mail Removed)>, Dirk Bruere at NeoPax wrote:

> I have an ArrayAdapter in main.
> How do I access it from another class?


If it’s from another class in the same source file, you have access by
default.

If it’s from a different source file, make it a public member.

This is all standard Java stuff, nothing peculiar to Android here.
 
Reply With Quote
 
Dirk Bruere at NeoPax
Guest
Posts: n/a
 
      03-31-2011
On 31/03/2011 03:42, Peter Duniho wrote:
> On 3/30/11 7:25 PM, Roedy Green wrote:
>> On Thu, 31 Mar 2011 02:03:24 +0100, Dirk Bruere at NeoPax
>> <(E-Mail Removed)> wrote, quoted or indirectly quoted someone who
>> said :
>>
>>> I have an ArrayAdapter in main.
>>> How do I access it from another class?

>>
>> You would have to show some code. I have never heard of an
>> ArrayAdapter.

>
> I assume he's referring to this:
> http://developer.android.com/referen...ayAdapter.html
>
> First link on Google and Bing.
>
> That said, it really doesn't matter what the type of the object is. It's
> still just going to be a normal object reference. And accessing object
> references that exist in one class from another class is always done the
> same way: either provide a method or field in the owning class that will
> return it, or pass/assign the value of the reference to a method/field
> in the accessing class.
>
> Basically, it's one of the first things someone ought to learn when
> learning how to program in an OOP language. Classes that can't get
> values from the instance of one class to the instance of another usually
> aren't that useful.
>
> Pete


Yes.
It's 04:49 here and my brain is not working too well.
Either its obvious, or I'm not explaining it correctly.
Tomorrow.

--
Dirk

http://www.neopax.com/technomage/ - My new book - Magick and Technology
 
Reply With Quote
 
Arved Sandstrom
Guest
Posts: n/a
 
      03-31-2011
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.

AHS
--
That's not the recollection that I recall...All this information is
certainly in the hands of the auditor and we certainly await his report
to indicate what he deems has occurred.
-- Halifax, Nova Scotia mayor Peter Kelly, who is currently deeply in
the ****
 
Reply With Quote
 
Andreas Leitgeb
Guest
Posts: n/a
 
      03-31-2011
Arved Sandstrom <(E-Mail Removed)> 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.

 
Reply With Quote
 
Dirk Bruere at NeoPax
Guest
Posts: n/a
 
      03-31-2011
On 31/03/2011 11:19, Andreas Leitgeb wrote:
> Arved Sandstrom<(E-Mail Removed)> 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<String>(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
 
Reply With Quote
 
Michal Kleczek
Guest
Posts: n/a
 
      03-31-2011
Dirk Bruere at NeoPax wrote:

>
> 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<String>(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?
>


There are so many issues with the code above that answering your direct
question does not make sense IMHO (but surely someone is going to answer it
and additionaly point out the issues).
So in hope to be bright and suggest you to search Google for an OOP tutorial
(possibly in Java) - I actually did:
http://www.google.pl/search?q=java+o...ammin+tutorial

And you know what - nothing really useful! A lot of material covering
(somewhat like in an encyclopedia) what an object/class/instance
variable/method is but nothing really _introductory_ that would illustrate
"live objects communicating with each other to achieve a goal".

Does anybody know of anything like this online?

--
Michal
 
Reply With Quote
 
Dirk Bruere at NeoPax
Guest
Posts: n/a
 
      03-31-2011
On 31/03/2011 12:52, Michal Kleczek wrote:
> Dirk Bruere at NeoPax wrote:
>
>>
>> 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<String>(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?
>>

>
> There are so many issues with the code above that answering your direct
> question does not make sense IMHO (but surely someone is going to answer it
> and additionaly point out the issues).
> So in hope to be bright and suggest you to search Google for an OOP tutorial
> (possibly in Java) - I actually did:
> http://www.google.pl/search?q=java+o...ammin+tutorial
>
> And you know what - nothing really useful! A lot of material covering
> (somewhat like in an encyclopedia) what an object/class/instance
> variable/method is but nothing really _introductory_ that would illustrate
> "live objects communicating with each other to achieve a goal".
>
> Does anybody know of anything like this online?
>


The problem is accessing something located in:
public void onCreate(Bundle savedInstanceState)

I thought I could do it with context.
I can certainly access (say)a ListView defined in onCreate by including
videoLV = (ListView )((Activity) mContext).findViewById(R.id.ListViewVideo);

in public BlinkAPI( Context ctx){}

I do not know a corresponding way to get an adapter

--
Dirk

http://www.neopax.com/technomage/ - My new book - Magick and Technology
 
Reply With Quote
 
Nigel Wade
Guest
Posts: n/a
 
      03-31-2011
On 31/03/11 12:21, Dirk Bruere at NeoPax wrote:

> private static void updateRadioTitles( ) {
>
> ...
> radioTitleAdapter.add(titleStr); //PROBLEM
> radioTitleAdapter.notifyDataSetChanged(); //PROBLEM
> }
>
> How do I get at radioTitleAdapter?
>


You ask whatever object knows where it is to let you have a copy of a
reference to it.

Since your code doesn't actually show that information I can't give
specific answers. But presumably some instance of class controller [sic]
knows where one can be found, since the onCreate() method of that class
creates one.

--
Nigel Wade
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments