使用ListAdapter显示数据库数据

时间:2010-06-22 06:13:50

标签: android database listview

public class List_View extends ListActivity {

    private TextView toptext; 
    private TextView bottomtext;

    DBAdapter db = new DBAdapter(this);

    public void onCreate(Bundle icicle)
    {
        super.onCreate(icicle);
        setContentView(R.layout.list);
        getData();

        toptext = (TextView) findViewById(R.id.toptext); 
        bottomtext = (TextView) findViewById(R.id.bottomtext); 

    }

    private void getData() {            
           db.open();

           Cursor c = db.getAllEntry();
           c.moveToFirst(); 

           ListAdapter adapter = new SimpleCursorAdapter(this,R.layout.view_list, c, new String[] {"date", "title"}, new int[] {R.id.toptext, R.id.bottomtext});

           bottomtext.setText(c.getString(1)); 
           toptext.setText(c.getString(4)); 

           setListAdapter(adapter);

           db.close(); 
    }

}

我想将数据库中存储的数据显示到ListView中。

仅限标题和日期。

1 个答案:

答案 0 :(得分:0)

只是瞥了一眼;你的getData调用位于toptext和bottomtext之前。