最近在做的一个项目需要展示一个页面,标题和内容,我以前虽然用过。但是是从手机本地数据库读的。现在是从公司PHP网站的服务器读龋原来用simpleCursorAdapter似乎不行了。在网上找了一些别人写的代码,但是总有一个疑问。他们写的ListActivity的子类都没有用setContentView,那么到底展示的是什么呢?这个让我很费解。后来自己试验发现,不用指定,显示的就是这个子类。
package com.example.listview;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.os.Bundle;
import android.app.ListActivity;
import android.widget.SimpleAdapter;
public class MyListView3 extends ListActivity {
// private List data = new ArrayList();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SimpleAdapter adapter = new SimpleAdapter(this,getData(),R.layout.vlist,
new String[]{title,info},
new int[]{R.id.title,R.id.info});
setListAdapter(adapter);
}
private List> getData() {
List> list = new ArrayList>();
Map map = new HashMap();
map.put(title, G1);
map.put(info, google 1);
list.add(map);
map = new HashMap();
map.put(title, G2);
map.put(info, google 2);
list.add(map);
map = new HashMap();
map.put(title, G3);
map.put(info, google 3);
list.add(map);
return list;
}
}
,>,>,>,>
vlist.xml:
效果: