我有一个返回一个对象超级简单列表中的Web服务
I have a web service that returns a super simple list of objects
为MyObject []数据= webServiceCall();
MyObject[] data = webServiceCall();
为MyObject有1场我想显示,名称
(即数据[0] .Name点
)
MyObject has 1 field i want to display, "Name"
(i.e. data[0].Name
)
我怎么能变成一个活动,列出了一个可滚动 listActivity
在Android上,这些对象只是名字这一点。我变得非常混淆的游标,我不知道我是否需要游标和我米不知道什么样的适配器来实现( BaseAdapter , SimpleAdapter
等)
How can i turn this into an activity that lists just the name of these objects in a scrollable listActivity
on Android. I am getting really confused with Cursors and am not sure if I need Cursors and I"m not sure what kind of adapter to implement (BaseAdapter
, SimpleAdapter
etc)
所以我想我正在寻找三样东西,
So i guess i'm looking for three things,
活动,适配器和 layout.xml
只是想弄清楚这个Android的东西出来,绝对是这里小白
Just trying to figure this android stuff out, definitely a noob here
所以我想我理解了它与RobGThai的回答一点启发,我张贴的$ C $下其他人看到,我想我并没有真正使用自定义适配器
so i think i figured it out with a little inspiration from RobGThai's answer, i'm posting the code for anyone else to see, i guess i didn't really use a custom adapter
这就是让我开始,所以一旦我有这个,我确信我的为MyObject对其有一个toString()方法,在列表中正确地显示,我顺利通过了MyObject的[]数组复制到超级简单的例子新ArrayAdapter的构造函数,而不是listItems中的
This is the super simple example that got me started, so once i had this, I made sure my "MyObject" had a toString() method on it to show properly in the list and i passed the MyObject[] array into the "new ArrayAdapter" constructor instead of listItems
FooList.java
FooList.java
import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
public class FooList extends ListActivity {
String[] listItems = {"item 1", "item 2 ", "list", "android", "item 3", "foobar", "bar", };
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.temp);
setListAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, listItems));
}
}
布局XML我用(temp.xml)
the layout xml i used (temp.xml)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:id="@android:id/list" android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<TextView android:id="@android:id/empty" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Empty set" />
</LinearLayout>