Android KSoap 强类型
我正在尝试将 ListView 绑定到 ASMX Web 服务,但是,我相信我没有正确布置列:
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
try {
super.onCreate(savedInstanceState);
ListView lstView = getListView();
lstView.setChoiceMode(2); //CHOICE_MODE_MULTIPLE
lstView.setTextFilterEnabled(true);
User[] u = GetUsers();
setListAdapter(new ArrayAdapter<User>(this, android.R.layout.simple_list_item_checked, u));
} catch (Exception e) {
e.printStackTrace();
}
}
我的 GetUsers() 方法返回以下内容:
User.Name = "joe";
User.Age = 30;
User.Name = "joe";
User.Age = 35;
数据返回正常,但是,我如何告诉ListView要绑定哪些列?
I am trying to bind ListView to an ASMX web service, however, I believe I'm not laying out the columns right:
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
try {
super.onCreate(savedInstanceState);
ListView lstView = getListView();
lstView.setChoiceMode(2); //CHOICE_MODE_MULTIPLE
lstView.setTextFilterEnabled(true);
User[] u = GetUsers();
setListAdapter(new ArrayAdapter<User>(this, android.R.layout.simple_list_item_checked, u));
} catch (Exception e) {
e.printStackTrace();
}
}
My GetUsers() method is returning the following:
User.Name = "joe";
User.Age = 30;
User.Name = "joe";
User.Age = 35;
The data is coming back fine, however, how do I tell the ListView which columns to bind?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您需要显示多于 1 列,您应该切换到
SimpleAdapter
或基于BaseAdapter
或ArrayAdapter< 实现自定义
ListAdapter
/代码>。我将扩展 ArrayAdapter 并覆盖那里的 getView 。这是官方示例 展示如何实现自定义适配器。但如果您只需要 1 列,您可以保留现有适配器并重写
User
类的toString()
方法,并返回您想要在列表中显示的字段。If you need to display more than 1 column, you should either switch to
SimpleAdapter
or implement customListAdapter
based onBaseAdapter
orArrayAdapter
. I'd extendArrayAdapter
and overridegetView
there. Here's the official samples showing how to implement custom adapter.But if you need only 1 column, you could keep your existing adapter and override
toString()
method of yourUser
class and return the field you wanna show in the list.