LinearLayout lv=(LinearLayout) findViewById(R.id.lv);
PersonDao dao=new PersonDao(this);
List<Person> persons=dao.select();
for(Person person:persons){
TextView tv=new TextView();
tv.setText(person.toString());
lv.addView(tv);
}
package com.tsh.database;
import java.util.List;
android.app.Activity;
android.os.Bundle;
android.util.Log;
android.view.View;
android.view.ViewGroup;
android.widget.BaseAdapter;
android.widget.ListView;
android.widget.TextView;
com.tsh.database.dao.PersonDao;
com.tsh.database.domain.Person;
public class MainActivity extends Activity {
private List<Person> persons;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView lv=(ListView) findViewById(R.id.mylist);
PersonDao dao=);
persons=dao.select();
lv.setAdapter(new MyAdapter());
}
private class MyAdapter BaseAdapter{
@Override
int getCount() {
// TODO Auto-generated method stub
return persons.size();
}
@Override
public Object getItem( position) {
return null;
}
@Override
long getItemId(return 0public View getView( position,View convertView,ViewGroup parent) {
Log.i("MainActivity","生成对象"+position);
TextView tv= TextView(getApplicationContext());
Person person=persons.get(position);
tv.setText(person.toString());
tv;
}
}
}