Android ListView详解(3)
public String toString() {
return "name: " + this.name + ", age:" + this.age;
}
}
3.接着是Activity代码
Java代码
package com.lamp.db;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.SimpleCursorAdapter;
import com.lamp.domain.Person;
import com.lamp.service.PersonService;
public class DBActivity extends Activity {
private ListView listView = null;
private PersonService personService = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
personService = new PersonService(this);
listView = (ListView) this.findViewById(R.id.listView);
List<HashMap<String, String>> data = new ArrayList<HashMap<String, String>>();
List<Person> personList = personService.getScrollData(0, 10);
HashMap<String,String> map = null;
for(Person person : personList){
map = new HashMap<String,String>();
map.put("personid", String.valueOf(person.getPersonid()));
map.put("name", person.getName());
map.put("age", String.valueOf(person.getAge()));
data.add(map);
}
SimpleAdapter simpleAdapter = new SimpleAdapter(this, data,
相关新闻>>
- 发表评论
-
- 最新评论 更多>>