正如标题所示。我做了一些研究并尝试了 jackson ,这似乎应该有效,但我在尝试使用它时遇到了荒谬的错误,所以这似乎是行不通的。
基本上我的问题是这样的,我的 ListView 由适配器填充,如下所示:
friendsArrayAdapter = new FriendsArrayAdapter(
NetPlay.this, R.layout.rowlayout, friends);
listView.setAdapter(friendsArrayAdapter);
friendsArrayAdapter.notifyDataSetChanged();
然后我想处理此 ListView 中的 onClick 事件,将该 ListView 的内容复制到变量中:
listView.setClickable(true);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int position, long arg3) {
Object o = listView.getItemAtPosition(position);
Object o = arg0.getItemAtPosition(position);
//mText.setText(o);
}
});
现在一切正常,但返回的值是实际的对象 ID/引用 显示为某事@Friends.21312。我想要的是实际内容,应该是名称+ID。
这是否可能,或者我是否需要重做我的整个 ListView 填充?
最佳答案
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
//friends is the array that is given to the Adapter.
//given friends = Friend[]
Friend f = friends[position];
f.getName();
f.getID();
}
这只是一个猜测,请发布您的完整代码以获得更好的帮助!
关于Java/Android,是否可以获取对象的内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11935197/