Reputation: 23
As part of an Activity, I have a class encapsulating functionality for a single object and want to display details of the object in a ListView
when a particular button is pressed.
Attempt One:
If I pass the ListView
and this
to the object to store (!) and then try to call the ArrayAdapter
, I get a runtime error:
Source not found
Code segment (method within the class)...
private void displayTouch(Touch lasttouch) {
String mLine = "";
/* Build up line of analysis */
...
/* Display line */
mAnalysis[lasttouch.mSequence] = mLine;
mViewAnalysis.setAdapter(new ArrayAdapter<String> (mActivity,R.layout.simplerow,mAnalysis));
} // End of method displayTouch
Attempt Two
If I try to display data in the ListView
from within the OnClick
Listener, I get an error message in Eclipse:
The constructor ArrayAdapter (new View.OnClickListener(){}, int, String[] is undefined.
Code segment (within the OnClick Listener of the Activity)...
/* Record details */
OnClickListener CourtListener = new OnClickListener() {
public void onClick(View v) {
...
/* Analyse */
...
/* Capture analysis */
lRoster.setAdapter(new ArrayAdapter<String> (this,R.layout.simplerow,playerArray));
} // End of event onClick
}; // End of listener CourtListener
In this code playerArray
is dimensioned within the Activity's onCreate
;
Both attempts have weaknesses of approach (in addition to not working) so I'll re-factor once I can get something working.
Essentially, how do I display data generated within an object to a ListView
within an Activity from the OnClick
Listener of another View in the same Activity? Everything is within one package and within the Activity.
Upvotes: 0
Views: 1452
Reputation: 424
Perhaps this blogpost might help: Putting custom objects in ListView
Upvotes: 1