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
On 31/03/2011 14:47, Nigel Wade wrote:
> 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.
>

Yes -I have worked out that bit but do not know what it is, esp since
other examples like ListView involve multiple casts

--
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 15:32, Dirk Bruere at NeoPax wrote:
> On 31/03/2011 14:47, Nigel Wade wrote:
>> 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.
>>

> Yes -I have worked out that bit but do not know what it is,


What what is?

Some instance of the "controller" class is creating that ArrayAdaptor.
So that instance knows what it created. Ask that instance for a copy of
the reference to the ArrayAdaptor it created. Or get it to act as proxy
and do the work for you by adding a method to that class which performs
the necessary operations on its local copy of the reference.

> esp since
> other examples like ListView involve multiple casts
>


???

--
Nigel Wade
 
Reply With Quote
 
 
 
 
Dirk Bruere at NeoPax
Guest
Posts: n/a
 
      03-31-2011
On 31/03/2011 15:42, Nigel Wade wrote:
> On 31/03/11 15:32, Dirk Bruere at NeoPax wrote:
>> On 31/03/2011 14:47, Nigel Wade wrote:
>>> 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.
>>>

>> Yes -I have worked out that bit but do not know what it is,

>
> What what is?
>
> Some instance of the "controller" class is creating that ArrayAdaptor.
> So that instance knows what it created. Ask that instance for a copy of
> the reference to the ArrayAdaptor it created. Or get it to act as proxy
> and do the work for you by adding a method to that class which performs
> the necessary operations on its local copy of the reference.


I know - but I cannot find out how to do it!

If I try to add this:
ArrayAdapter<String> getArrayAdapter(){
return radioTitleAdapter;
}
I get an error: "Syntax error on tokens, misplaced constructs".
I don't have a clue what it means

--
Dirk

http://www.neopax.com/technomage/ - My new book - Magick and Technology
 
Reply With Quote
 
markspace
Guest
Posts: n/a
 
      03-31-2011
On 3/31/2011 8:35 AM, Dirk Bruere at NeoPax wrote:

> If I try to add this:
> ArrayAdapter<String> getArrayAdapter(){
> return radioTitleAdapter;
> }
> I get an error: "Syntax error on tokens, misplaced constructs".
> I don't have a clue what it means



Huh. Isn't that sad.

And yet the error doesn't motivate you enough to produce an SSCCE that
would actually allow us to help you out.

Bummer.

Sorry to be sarcastic, but jumping Jesus H. ****ing Christ on a Pogo
stick people, do you even know enough about code to be able to write a
program that compiles? And maybe even re-produces the error? Just to
be clear: I'm not motivated in any way, shape or form to even attempt to
help you until you can at least manage something close to program that
reproduces the error. Your wasting your time by posting nonsense until
you can at least do that.

 
Reply With Quote
 
Andreas Leitgeb
Guest
Posts: n/a
 
      03-31-2011
Dirk Bruere at NeoPax <> wrote:
> 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) {
> [...]
> radioTitleAdapter = new ArrayAdapter<String>([...]);
> [...]
> }
> ...
> }


With an IDE you could probably also right-click on the identifier
and select "Jump to declaration" or something similar.

For Vi and Emacs there's something like a tags file, that enables
similar functionality, provided you created/updated that tags file
e.g. with the utility "ctags-exuberant", and press a hotkey when
the cursor is on the identifier (for VI, that would be <Ctrl-]>).

Finally, you can also grep for the identifier, but that depends on
that you filter out with your eyes the declaration from all the
other lines containing it.

Once you found the declaration, you're a good step ahead towards
solving your problem. If you then post the complete declaration line
and the class or method containing it ... help might be possible.

 
Reply With Quote
 
John B. Matthews
Guest
Posts: n/a
 
      03-31-2011
In article <in1ptj$dsv$>,
Michal Kleczek <> wrote:

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


Excellent question. I recall starting with the Sun/Oracle tutorial:

<http://download.oracle.com/javase/tutorial/java/concepts/>

In contrast, this series offered a broader perspective and greater
depth, IMO:

<http://www.dickbaldwin.com/tocint.htm>

--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>
 
Reply With Quote
 
Dirk Bruere at NeoPax
Guest
Posts: n/a
 
      03-31-2011
On 31/03/2011 18:09, Patricia Shanahan wrote:
> On 3/31/2011 8:35 AM, Dirk Bruere at NeoPax wrote:
> ...
>> I get an error: "Syntax error on tokens, misplaced constructs".

>
> It probably means that you put the construct somewhere where it is not
> permitted by the Java syntax. The actual issue, and what you need to do
> to fix it, depends on where you put it in your code.
>
> Patricia


Let's start again with my latest code that also does not work

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);


lvRadio = (ListView)findViewById(R.id.ListViewRadio);
}
...
}

public class BlinkAPI {

private static Context mContext;
static ListView radioLV;


public BlinkAPI( Context ctx)
{
BlinkAPI.mContext = ctx;

radioLV = (ListView )((Activity)
mContext).findViewById(R.id.ListViewRadio);

}

private static void updateRadioTitles( ) {
radioTitleAdapter = (ArrayAdapter<String>)
radioLV.getAdapter();
...//Get titleStr etc
radioTitleAdapter.add(titleStr);
radioTitleAdapter.notifyDataSetChanged();
}

This code crashes out

--
Dirk

http://www.neopax.com/technomage/ - My new book - Magick and Technology
 
Reply With Quote
 
Dirk Bruere at NeoPax
Guest
Posts: n/a
 
      03-31-2011
On 31/03/2011 21:26, Dirk Bruere at NeoPax wrote:
> On 31/03/2011 18:09, Patricia Shanahan wrote:
>> On 3/31/2011 8:35 AM, Dirk Bruere at NeoPax wrote:
>> ...
>>> I get an error: "Syntax error on tokens, misplaced constructs".

>>
>> It probably means that you put the construct somewhere where it is not
>> permitted by the Java syntax. The actual issue, and what you need to do
>> to fix it, depends on where you put it in your code.
>>
>> Patricia

>
> Let's start again with my latest code that also does not work

To clarify a bit more

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);


lvRadio = (ListView)findViewById(R.id.ListViewRadio);
}
...
}
//************************************************** **************************
//Different file
//************************************************** **************************

public class BlinkAPI {

private static Context mContext;
static ListView radioLV;


public BlinkAPI( Context ctx)
{
BlinkAPI.mContext = ctx;

radioLV = (ListView )((Activity)
mContext).findViewById(R.id.ListViewRadio);

}

private static void updateRadioTitles( ) {
radioTitleAdapter = (ArrayAdapter<String>)
radioLV.getAdapter();
...//Get titleStr etc
radioTitleAdapter.add(titleStr);
radioTitleAdapter.notifyDataSetChanged();
}

This code crashes out


--
Dirk

http://www.neopax.com/technomage/ - My new book - Magick and Technology
 
Reply With Quote
 
markspace
Guest
Posts: n/a
 
      03-31-2011
On 3/31/2011 1:50 PM, Patricia Shanahan wrote:

> Either you have serious problems with program structure that would
> prevent compilation or you have problems pasting code into articles.


I'm guessing this time it's the latter.

>>
>> This code crashes out


This didn't end with a period which is uncharacteristic for the OP. I
think his newsreader just failed, is all.


To the OP: bits like these below:

>> ...//Get titleStr etc


>> lvRadio = (ListView)findViewById(R.id.ListViewRadio);
>> }
>> ...


won't ever compile. Please remove the ...'s and post code that does
compile, or at least shows what error with the compiler you are actually
having.

 
Reply With Quote
 
Dirk Bruere at NeoPax
Guest
Posts: n/a
 
      03-31-2011
> Try to strip out everything you can and still reproduce the problem you
> are asking about, and then paste into an article *exactly* the code for
> which you want help.
>
> Patricia


OK - here's the revision

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);


ListView lvRadio = (ListView)findViewById(R.id.ListViewRadio);
}
...
}

//Everything below is in a separate file

public class BlinkAPI
{

private static Context mContext;
static ListView radioLV;
static ArrayList<String> radioTitleArrayList = new ArrayList<String>();



public BlinkAPI( Context ctx)
{
BlinkAPI.mContext = ctx;
radioLV = (ListView )((Activity)
mContext).findViewById(R.id.ListViewRadio);

}

private static void updateRadioTitles( )
{
ArrayAdapter<String> radioTitleAdapter = new
ArrayAdapter<String>(mContext,
android.R.layout.simple_expandable_list_item_1,rad ioTitleArrayList);
...//Get titleStr etc
radioTitleAdapter.add(titleStr);
radioTitleAdapter.notifyDataSetChanged();
}
}

--
Dirk

http://www.neopax.com/technomage/ - My new book - Magick and Technology
 
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
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57