在 Android 中的 ListView 中显示对象详细信息
作为 Activity 的一部分,我有一个封装单个对象功能的类,并且希望在按下特定按钮时在 ListView
中显示该对象的详细信息。
尝试一:
如果我将 ListView
和 this
传递给要存储的对象(!),然后尝试调用 ArrayAdapter< /code>,我收到运行时错误:
未找到来源
代码段(类内的方法)...
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
尝试二
如果我尝试从OnClick
中显示ListView
中的数据听众,我在 Eclipse 中收到一条错误消息:
构造函数ArrayAdapter(new View.OnClickListener(){}, int, String[]未定义。
代码段(在 Activity 的 OnClick 侦听器内)...
/* 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
在此代码中,playerArray
的尺寸在Activity 的 onCreate ;
这两种尝试都有方法的弱点(除了不起作用),所以一旦我能得到一些东西,我就会重新考虑,
本质上,如何将对象中生成的数据显示出来 。活动中的 ListView
来自同一活动中另一个视图的 OnClick
侦听器?一切都在同一个包和活动中。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许这篇博文可能会有所帮助:将自定义对象放入列表视图
Perhaps this blogpost might help: Putting custom objects in ListView