是否有一个超级简单的列表/ ListAdapter例如在那里为Android [英] Is there a super simple List / ListAdapter example out there for android

查看:122
本文介绍了是否有一个超级简单的列表/ ListAdapter例如在那里为Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个返回一个对象超级简单列表中的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上,这些对象只是名字这一点。我变得非常混淆的游标,我不知道我是否需要游标和我米不知道什么样的适配器来实现(<$ C C $> 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>

这篇关于是否有一个超级简单的列表/ ListAdapter例如在那里为Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆